def get_matchups(self, key_map=None): """ Request the matchups for each week of this season from the Sleeper API :param key_map: A dictionary representing the values to be parsed from the API responses :return: A DataFrame representing all the matchups from this season """ all_matchups = list() for week in range( self.start_week, self.playoff_start_week + self.playoff_rounds_count, ): url = f"{self.base_url}/league/{self.season_id}/matchups/{week}" response = api_get_request(url) if key_map: response = format_response(response, key_map) week_matchups = pd.DataFrame(response) week_matchups["season_id"] = self.season_id week_matchups["week"] = week all_matchups.append(pd.DataFrame(week_matchups)) self.matchups = pd.concat(all_matchups, ignore_index=True) return self.matchups
def get_rosters(self, key_map=None): """ Request the rosters for this season from the Sleeper API :param key_map: A dictionary representing the values to be parsed from the API response :return: A DataFrame representing the rosters """ url = f"{self.base_url}/league/{self.season_id}/rosters" response = api_get_request(url) if key_map: response = format_response(response, key_map) rosters = pd.DataFrame(response) rosters["season_id"] = self.season_id self.rosters = rosters return self.rosters
def get_draft_picks(self, key_map=None): """ Request the full list of draft picks from a particular draft from the Sleeper API :param key_map: A dictionary representing the values to be parsed from the API response :return: A DataFrame representing the draft picks """ url = f"{self.base_url}/draft/{self.draft_id}/picks" response = api_get_request(url) if key_map: response = format_response(response, key_map) draft_picks = pd.DataFrame(response) draft_picks["season_id"] = self.season_id self.draft_picks = draft_picks return self.draft_picks
def get_winners_bracket(self, key_map=None): """ Request the playoff winner's bracket for this season from the Sleeper API :param key_map: A dictionary representing the values to be parsed from the API response :return: A DataFrame representing the winner's bracket """ url = f"{self.base_url}/league/{self.season_id}/winners_bracket" response = api_get_request(url) self.playoff_rounds_count = max([matchup["r"] for matchup in response]) if key_map: response = format_response(response, key_map) winners_bracket = pd.DataFrame(response) winners_bracket["season_id"] = self.season_id self.winners_bracket = winners_bracket return self.winners_bracket
def get_season(self, key_map=None): """ Request a season from the Sleeper API :param key_map: A dictionary representing the values to be parsed from the API response :return: A DataFrame representing the season """ url = f"{self.base_url}/league/{self.season_id}" response = api_get_request(url) self.year = int(response.get("season")) self.previous_season_id = response.get("previous_league_id") self.draft_id = response.get("draft_id") settings = response.get("settings", dict()) self.start_week = settings.get("start_week") self.playoff_start_week = settings.get("playoff_week_start") if key_map: response = format_response(response, key_map) self.season = pd.DataFrame([response]) self.season["year"] = self.season["year"].astype(int) self.season["league_name"] = self.league_name return self.season