def fetch_current_season(self, region, timeout=60): """ Fetch current season information. :return: <status code, ApiSeasonInfo or None, fetch time, fetch duration> """ url_prefix = self.REGION_URL_PREFIXES_2[region] url = '%s/season/current' % url_prefix timer = Timer() status, data = self.http_get_json(url, timeout, ACCESS_TOKEN_AUTH) return SeasonResponse(status, ApiSeason(data, url), utcnow(), timer.end())
def fetch_player_ladders(self, region, player_path, timeout=60): """ Fetch player ladders from blizzard api. :return: <status code, ApiPlayerLadders or None, fetch time, fetch duration> """ url_prefix = self.REGION_URL_PREFIXES_1[region] url = '%s%sladders' % (url_prefix, player_path) timer = Timer() status, data = self.http_get_json(url, timeout, API_KEY_AUTH) return PlayerLaddersResponse(status, ApiPlayerLadders(data, url), utcnow(), timer.end())
def fetch_ladder(self, region, bid, timeout=60): """ Fetch ladder from blizzard api. :return: <status code, ApiLadder or None, fetch time, fetch duration> """ url_prefix = self.REGION_URL_PREFIXES[region] url = f"{url_prefix}/data/sc2/ladder/{bid}" timer = Timer() status, data = self.http_get_json(url, timeout, ACCESS_TOKEN_AUTH) al = ApiLadder(data, url) return LadderResponse(status, al, utcnow(), timer.end())
def fetch_ladder(self, season_id, region, bid, timeout=60): """ Fetch ladder from blizzard api. :return: <status code, ApiLadder or None, fetch time, fetch duration> """ if season_id >= 28: url_prefix = self.REGION_URL_PREFIXES_2[region] url = "%s/ladder/%d" % (url_prefix, bid) timer = Timer() status, data = self.http_get_json(url, timeout, ACCESS_TOKEN_AUTH) else: url_prefix = self.REGION_URL_PREFIXES_1[region] url = "%s/ladder/%d" % (url_prefix, bid) timer = Timer() status, data = self.http_get_json(url, timeout, API_KEY_AUTH) al = ApiLadder(data, url) return LadderResponse(status, al, utcnow(), timer.end())
def fetch_league(self, region, season_id, version, mode, league, timeout=60): """ Fetch league information. :return: <status code, ApiLeagueInfo or None, fetch time, fetch duration> """ url_prefix = self.REGION_URL_PREFIXES[region] queue_id = self.QUEUE_ID_MAJOR[version] + self.QUEUE_ID_MINOR[mode] team_type = self.TEAM_TYPE[mode] url = f'{url_prefix}/data/sc2/league/{season_id}/{queue_id}/{team_type}/{league}' bid = league + team_type * 10 + queue_id * 100 + season_id * 100000 timer = Timer() status, data = self.http_get_json(url, timeout, ACCESS_TOKEN_AUTH) return LeagueResponse(status, ApiLeague(data, url, bid), utcnow(), timer.end())