Skip to content

Commit

Permalink
Basketball Pass Pro Schedule on Team Init
Browse files Browse the repository at this point in the history
  • Loading branch information
cwendt94 committed Nov 4, 2022
1 parent bd6b00c commit e647bab
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions espn_api/base_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _fetch_league(self, SettingsClass = BaseSettings):
self.settings = SettingsClass(data['settings'])
return data

def _fetch_teams(self, data, TeamClass):
def _fetch_teams(self, data, TeamClass, pro_schedule = None):
'''Fetch teams in league'''
self.teams = []
teams = data['teams']
Expand All @@ -61,7 +61,7 @@ def _fetch_teams(self, data, TeamClass):
elif member['id'] == team['owners'][0]:
break
roster = team_roster[team['id']]
self.teams.append(TeamClass(team, roster=roster, member=member, schedule=schedule, year=seasonId))
self.teams.append(TeamClass(team, roster=roster, member=member, schedule=schedule, year=seasonId, pro_schedule=pro_schedule))

# sort by team ID
self.teams = sorted(self.teams, key=lambda x: x.team_id, reverse=False)
Expand Down
2 changes: 1 addition & 1 deletion espn_api/baseball/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Team(object):
'''Teams are part of the league'''
def __init__(self, data, member, roster, schedule, year):
def __init__(self, data, member, roster, schedule, year, **kwargs):
self.team_id = data['id']
self.team_abbrev = data['abbrev']
self.team_name = "%s %s" % (data['location'], data['nickname'])
Expand Down
5 changes: 3 additions & 2 deletions espn_api/basketball/league.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ def _map_matchup_ids(self, schedule):


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

# replace opponentIds in schedule with team instances
for team in self.teams:
Expand Down
8 changes: 4 additions & 4 deletions espn_api/basketball/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Team(object):
'''Teams are part of the league'''
def __init__(self, data, member, roster, schedule, year):
def __init__(self, data, member, roster, schedule, year, **kwargs):
self.team_id = data['id']
self.team_abbrev = data['abbrev']
self.team_name = "%s %s" % (data['location'], data['nickname'])
Expand All @@ -29,20 +29,20 @@ def __init__(self, data, member, roster, schedule, year):
if 'logo' in data:
self.logo_url = data['logo']

self._fetch_roster(roster, year)
self._fetch_roster(roster, year, kwargs.get('pro_schedule'))
self._fetch_schedule(schedule)

def __repr__(self):
return f'Team({self.team_name})'


def _fetch_roster(self, data, year):
def _fetch_roster(self, data, year, pro_schedule = None):
'''Fetch teams roster'''
self.roster.clear()
roster = data['entries']

for player in roster:
self.roster.append(Player(player, year))
self.roster.append(Player(player, year, pro_schedule))


def _fetch_schedule(self, data):
Expand Down
2 changes: 1 addition & 1 deletion espn_api/football/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Team(object):
'''Teams are part of the league'''
def __init__(self, data, roster, member, schedule, year):
def __init__(self, data, roster, member, schedule, year, **kwargs):
self.team_id = data['id']
self.team_abbrev = data['abbrev']
self.team_name = "%s %s" % (data['location'], data['nickname'])
Expand Down
2 changes: 1 addition & 1 deletion espn_api/hockey/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Team(object):
'''Teams are part of the league'''

def __init__(self, data, member, roster, schedule, year):
def __init__(self, data, member, roster, schedule, year, **kwargs):
self.team_id = data['id']
self.team_abbrev = data['abbrev']
self.team_name = "%s %s" % (data['location'], data['nickname'])
Expand Down
2 changes: 1 addition & 1 deletion espn_api/wbasketball/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Team(object):
'''Teams are part of the league'''
def __init__(self, data, member, roster, schedule, year):
def __init__(self, data, member, roster, schedule, year, **kwargs):
self.team_id = data['id']
self.team_abbrev = data['abbrev']
self.team_name = "%s %s" % (data['location'], data['nickname'])
Expand Down
2 changes: 2 additions & 0 deletions tests/basketball/integration/test_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ def test_league_init(self):
league = League(411647, 2019)

self.assertEqual(league.scoringPeriodId, 178)
player = league.teams[0].roster[0]
self.assertAlmostEqual(player.schedule['2']['team'], 'BKN')

def test_league_scoreboard(self):
league = League(411647, 2019)
Expand Down

0 comments on commit e647bab

Please sign in to comment.