Skip to content

Commit

Permalink
Merge pull request #631 from JohnDiebold/basketball_fix_multiple_pro_…
Browse files Browse the repository at this point in the history
…schedule_requests

bugfix/Fix multiple pro schedule requests
  • Loading branch information
cwendt94 authored Feb 7, 2025
2 parents 805ba67 + 543309c commit 9c0f586
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions espn_api/basketball/league.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def _map_matchup_ids(self, schedule):

def _fetch_teams(self, data):
'''Fetch teams in league'''
pro_schedule = self._get_all_pro_schedule()
super()._fetch_teams(data, TeamClass=Team, pro_schedule=pro_schedule)
self.pro_schedule = self._get_all_pro_schedule()
super()._fetch_teams(data, TeamClass=Team, pro_schedule=self.pro_schedule)

# replace opponentIds in schedule with team instances
for team in self.teams:
Expand Down Expand Up @@ -184,8 +184,7 @@ def box_scores(self, matchup_period: int = None, scoring_period: int = None, mat
data = self.espn_request.league_get(params=params, headers=headers)

schedule = data['schedule']
pro_schedule = self._get_all_pro_schedule()
box_data = [self.BoxScoreClass(matchup, pro_schedule, matchup_total, self.year, scoring_id) for matchup in schedule]
box_data = [self.BoxScoreClass(matchup, self.pro_schedule, matchup_total, self.year, scoring_id) for matchup in schedule]

for team in self.teams:
for matchup in box_data:
Expand All @@ -207,14 +206,12 @@ def player_info(self, name: str = None, playerId: Union[int, list] = None, inclu

data = self.espn_request.get_player_card(playerId, self.finalScoringPeriod)

pro_schedule = self._get_all_pro_schedule()

if include_news:
news = {}
for id in playerId:
news[id] = self.espn_request.get_player_news(id)

if len(data['players']) == 1:
return Player(data['players'][0], self.year, pro_schedule, news=news.get(playerId[0], []) if include_news else None)
return Player(data['players'][0], self.year, self.pro_schedule, news=news.get(playerId[0], []) if include_news else None)
if len(data['players']) > 1:
return [Player(player, self.year, pro_schedule, news=news.get(player['id'], []) if include_news else None) for player in data['players']]
return [Player(player, self.year, self.pro_schedule, news=news.get(player['id'], []) if include_news else None) for player in data['players']]

0 comments on commit 9c0f586

Please sign in to comment.