From 97965b5a70b3aa94b8d627501b3e5b932db57f7b Mon Sep 17 00:00:00 2001 From: Nathan Abraham Date: Wed, 25 Dec 2019 14:49:35 -0500 Subject: [PATCH] Add features to matchups; Fix a bug in player parsing - Matchups tell you the winner of each week - Matchups tell you if the game is a playoff game (winner's bracket) - Null check the player position dictionary before using it --- ff_espn_api/league.py | 2 ++ ff_espn_api/matchup.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/ff_espn_api/league.py b/ff_espn_api/league.py index 9810d5b8..c31908be 100644 --- a/ff_espn_api/league.py +++ b/ff_espn_api/league.py @@ -349,6 +349,8 @@ def scoreboard(self, week: int = None) -> List[Matchup]: for team in self.teams: for matchup in matchups: + if matchup.winner == team.team_id: + matchup.winner = team if matchup.home_team == team.team_id: matchup.home_team = team elif matchup.away_team == team.team_id: diff --git a/ff_espn_api/matchup.py b/ff_espn_api/matchup.py index 7fedbeb4..74395ffb 100644 --- a/ff_espn_api/matchup.py +++ b/ff_espn_api/matchup.py @@ -1,3 +1,6 @@ +WINNERS_BRACKET = 'WINNERS_BRACKET' + + class Matchup(object): '''Creates Matchup instance''' def __init__(self, data): @@ -7,6 +10,9 @@ def __init__(self, data): def __repr__(self): return 'Matchup(%s, %s)' % (self.home_team, self.away_team, ) + def is_playoff(self): + return WINNERS_BRACKET == self.playoff_tier_type + def _fetch_matchup_info(self): '''Fetch info for matchup''' self.home_team = self.data['home']['teamId'] @@ -18,3 +24,5 @@ def _fetch_matchup_info(self): if 'away' in self.data: self.away_team = self.data['away']['teamId'] self.away_score = self.data['away']['totalPoints'] + self.playoff_tier_type = self.data.get('playoffTierType', 'regular') + self.winner = self.home_team if self.data['winner'] == 'HOME' else self.away_team