示例#1
0
    async def get_player_recent_matches(self, account_id: StrOrInt) -> List[PlayerRecentMatch]:
        """GET /players/{account_id}/recentMatches

         https://docs.opendota.com/#tag/players%2Fpaths%2F~1players~1%7Baccount_id%7D~1recentMatches%2Fget
        """
        url = f'{OPEN_DOTA_API_URL}/players/{account_id}/recentMatches'
        data = await get_url_json_with_file_cache(url, params=self._params, lifetime=5 * 60)
        return spec.load(List[PlayerRecentMatch], data)
示例#2
0
    async def get_hero_matchups(self, hero_id: StrOrInt) -> List[HeroMatchup]:
        """GET /heroes/{hero_id}/matchups

         https://docs.opendota.com/#tag/heroes%2Fpaths%2F~1heroes~1%7Bhero_id%7D~1matchups%2Fget
         https://blog.opendota.com/2016/09/30/explaining-rankings/
        """
        url = f'{OPEN_DOTA_API_URL}/heroes/{hero_id}/matchups'
        data = await get_url_json_with_file_cache(url, params=self._params, lifetime=3 * 24 * 60 * 60)
        return spec.load(List[HeroMatchup], data)
示例#3
0
    async def request_match_parse(self, match_id: StrOrInt) -> JobStatus:
        """POST /request/{match_id}

        https://docs.opendota.com/#tag/request%2Fpaths%2F~1request~1%7Bmatch_id%7D%2Fpost
        """
        url = f'{OPEN_DOTA_API_URL}/request/{match_id}'
        async with aiohttp.ClientSession() as session:
            resp = await session.post(url, params=self._params)
            data = await resp.json(encoding='utf-8')
            return spec.load(JobStatus, data)
示例#4
0
    async def get_match(
            self,
            match_id: StrOrInt,
            cache_lifetime: float = 24 * 60 * 60
    ) -> DotaMatch:
        """GET /matches/{match_id}  (cached)

        https://docs.opendota.com/#tag/matches%2Fpaths%2F~1matches~1%7Bmatch_id%7D%2Fget
        """
        url = f'{OPEN_DOTA_API_URL}/matches/{match_id}'
        data = await get_url_json_with_file_cache(
            url,
            params=self._params,
            lifetime=cache_lifetime
        )
        return spec.load(DotaMatch, data)
示例#5
0
async def get_item_ids() -> Dict[str, DotaItem]:
    data = await get_url_json_with_file_cache(
        'https://raw.githubusercontent.com/odota/dotaconstants/master/build/item_ids.json'
    )
    return spec.load(Dict[str, str], data)