diff --git a/espn_api/football/box_player.py b/espn_api/football/box_player.py index 297857c7..e637c999 100644 --- a/espn_api/football/box_player.py +++ b/espn_api/football/box_player.py @@ -26,14 +26,16 @@ def __init__(self, data, pro_schedule, positional_rankings, week): self.pro_pos_rank = positional_rankings[posId][str(opp_id)] if str(opp_id) in positional_rankings[posId] else 0 - player_stats = player['stats'] + player_stats = player.get('stats') for stats in player_stats: - if stats['statSourceId'] == 0 and stats['scoringPeriodId'] == week: - self.points = round(stats['appliedTotal'], 2) - self.points_breakdown = {PLAYER_STATS_MAP.get(int(k), k):v for (k,v) in stats['appliedStats'].items()} - elif stats['statSourceId'] == 1 and stats['scoringPeriodId'] == week: - self.projected_points = round(stats['appliedTotal'], 2) - self.projected_breakdown = {PLAYER_STATS_MAP.get(int(k), k):v for (k,v) in stats['appliedStats'].items()} + stats_breakdown = stats.get('appliedStats') if stats.get('appliedStats') else stats.get('stats', {}) + points = round(stats.get('appliedTotal', 0), 2) + if stats.get('statSourceId') == 0 and stats.get('scoringPeriodId') == week: + self.points = points + self.points_breakdown = {PLAYER_STATS_MAP.get(int(k), k):v for (k,v) in stats_breakdown.items()} + elif stats.get('statSourceId') == 1 and stats.get('scoringPeriodId') == week: + self.projected_points = points + self.projected_breakdown = {PLAYER_STATS_MAP.get(int(k), k):v for (k,v) in stats_breakdown.items()} diff --git a/setup.py b/setup.py index 4cd172d4..7aa34297 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name='espn_api', packages=find_packages(), - version='0.4.1', + version='0.4.2', author='Christian Wendt', description='ESPN API', install_requires=['requests>=2.0.0,<3.0.0'],