diff --git a/espn_api/base_league.py b/espn_api/base_league.py index 55f56c7d..64767433 100644 --- a/espn_api/base_league.py +++ b/espn_api/base_league.py @@ -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'] @@ -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) diff --git a/espn_api/baseball/team.py b/espn_api/baseball/team.py index 3941f8fc..fc7e7901 100644 --- a/espn_api/baseball/team.py +++ b/espn_api/baseball/team.py @@ -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']) diff --git a/espn_api/basketball/league.py b/espn_api/basketball/league.py index b499e877..e5d21850 100644 --- a/espn_api/basketball/league.py +++ b/espn_api/basketball/league.py @@ -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: diff --git a/espn_api/basketball/team.py b/espn_api/basketball/team.py index 42376214..3413c71e 100644 --- a/espn_api/basketball/team.py +++ b/espn_api/basketball/team.py @@ -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']) @@ -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): diff --git a/espn_api/football/team.py b/espn_api/football/team.py index dbcadd13..d09c729b 100644 --- a/espn_api/football/team.py +++ b/espn_api/football/team.py @@ -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']) diff --git a/espn_api/hockey/team.py b/espn_api/hockey/team.py index c8c7341a..90a06dc6 100644 --- a/espn_api/hockey/team.py +++ b/espn_api/hockey/team.py @@ -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']) diff --git a/espn_api/wbasketball/team.py b/espn_api/wbasketball/team.py index b8e009eb..801e2449 100644 --- a/espn_api/wbasketball/team.py +++ b/espn_api/wbasketball/team.py @@ -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']) diff --git a/tests/basketball/integration/test_league.py b/tests/basketball/integration/test_league.py index e18a20f8..b5c0fca4 100644 --- a/tests/basketball/integration/test_league.py +++ b/tests/basketball/integration/test_league.py @@ -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)