Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding owners to Team #487

Merged
merged 5 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion espn_api/base_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def __init__(self, league_id: int, year: int, sport: str, espn_s2=None, swid=Non
self.league_id = league_id
self.year = year
self.teams = []
self.members = []
self.draft = []
self.player_map = {}

Expand All @@ -38,6 +39,7 @@ def _fetch_league(self, SettingsClass = BaseSettings):
else:
self.current_week = self.scoringPeriodId if self.scoringPeriodId <= data['status']['finalScoringPeriod'] else data['status']['finalScoringPeriod']
self.settings = SettingsClass(data['settings'])
self.members = data['members']
return data

def _fetch_teams(self, data, TeamClass, pro_schedule = None):
Expand All @@ -48,12 +50,15 @@ def _fetch_teams(self, data, TeamClass, pro_schedule = None):
seasonId = data['seasonId']

team_roster = {}
team_owners = {}
for team in data['teams']:
team_roster[team['id']] = team.get('roster', {})
team_owners[team['id']] = team.get('owners', [])

for team in teams:
roster = team_roster[team['id']]
self.teams.append(TeamClass(team, roster=roster, schedule=schedule, year=seasonId, pro_schedule=pro_schedule))
owners = team_owners[team['id']]
bnm91 marked this conversation as resolved.
Show resolved Hide resolved
self.teams.append(TeamClass(team, roster=roster, schedule=schedule, year=seasonId, pro_schedule=pro_schedule, owners=owners))

# sort by team ID
self.teams = sorted(self.teams, key=lambda x: x.team_id, reverse=False)
Expand Down
3 changes: 2 additions & 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, roster, schedule, year, **kwargs):
def __init__(self, data, roster, schedule, year, owners, **kwargs):
self.team_id = data['id']
bnm91 marked this conversation as resolved.
Show resolved Hide resolved
self.team_abbrev = data['abbrev']
if year < 2023:
Expand All @@ -27,6 +27,7 @@ def __init__(self, data, roster, schedule, year, **kwargs):

self._fetch_roster(roster)
self._fetch_schedule(schedule)
self.owners = owners

def __repr__(self):
return f'Team({self.team_name})'
Expand Down
3 changes: 2 additions & 1 deletion espn_api/basketball/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, roster, schedule, year, **kwargs):
def __init__(self, data, roster, schedule, year, owners, **kwargs):
self.team_id = data['id']
self.team_abbrev = data['abbrev']
if year < 2023:
Expand All @@ -30,6 +30,7 @@ def __init__(self, data, roster, schedule, year, **kwargs):

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

def __repr__(self):
return f'Team({self.team_name})'
Expand Down
3 changes: 2 additions & 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, schedule, year, **kwargs):
def __init__(self, data, roster, schedule, year, owners, **kwargs):
self.team_id = data['id']
self.team_abbrev = data['abbrev']
if year < 2023:
Expand Down Expand Up @@ -37,6 +37,7 @@ def __init__(self, data, roster, schedule, year, **kwargs):
self.mov = []
self._fetch_schedule(schedule)
self._fetch_roster(roster, year)
self.owners = owners

def __repr__(self):
return 'Team(%s)' % (self.team_name, )
Expand Down
3 changes: 2 additions & 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, roster, schedule, year, **kwargs):
def __init__(self, data, roster, schedule, year, owners, **kwargs):
self.team_id = data['id']
self.team_abbrev = data['abbrev']
if year < 2023:
Expand Down Expand Up @@ -34,6 +34,7 @@ def __init__(self, data, roster, schedule, year, **kwargs):

self._fetch_roster(roster)
self._fetch_schedule(schedule)
self.owners = owners

def __repr__(self):
return 'Team(%s)' % (self.team_name,)
Expand Down
3 changes: 2 additions & 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, roster, schedule, year, **kwargs):
def __init__(self, data, roster, schedule, year, owners, **kwargs):
self.team_id = data['id']
self.team_abbrev = data['abbrev']
if year < 2023:
Expand All @@ -31,6 +31,7 @@ def __init__(self, data, roster, schedule, year, **kwargs):

self._fetch_roster(roster, year)
self._fetch_schedule(schedule)
self.owners = owners

def __repr__(self):
return f'Team({self.team_name})'
Expand Down
5 changes: 3 additions & 2 deletions tests/hockey/unit/test_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ def setUp(self) -> None:

self.team = self.data['teams'][3]
self.team_roster = self.team['roster']
self.owners = self.team['owners']

def test_team(self):
team = Team(self.team, roster= self.team_roster, schedule= self.schedule, year= self.year)
team = Team(self.team, roster= self.team_roster, schedule= self.schedule, year= self.year, owners=self.owners)
self.assertEqual(team.team_abbrev, 'ESPC')

def test_team_roster_df(self):
team = Team(self.team, roster= self.team_roster, schedule= self.schedule, year= self.year)
team = Team(self.team, roster= self.team_roster, schedule= self.schedule, year= self.year, owners=self.owners)

self.assertEqual(len(team.roster), 25)
self.assertEqual(team.roster[0].name, 'Thomas Chabot')
Expand Down