Skip to content

Commit

Permalink
moving logic to Team
Browse files Browse the repository at this point in the history
  • Loading branch information
bnm91 committed Oct 26, 2023
1 parent 1910e15 commit 0aef069
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 17 deletions.
5 changes: 1 addition & 4 deletions espn_api/base_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,12 @@ 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']]
owners = team_owners[team['id']]
self.teams.append(TeamClass(team, roster=roster, schedule=schedule, year=seasonId, pro_schedule=pro_schedule, owners=owners))
self.teams.append(TeamClass(team, roster=roster, 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
4 changes: 2 additions & 2 deletions 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, owners, **kwargs):
def __init__(self, data, roster, schedule, year, **kwargs):
self.team_id = data['id']
self.team_abbrev = data['abbrev']
if year < 2023:
Expand All @@ -27,7 +27,7 @@ def __init__(self, data, roster, schedule, year, owners, **kwargs):

self._fetch_roster(roster)
self._fetch_schedule(schedule)
self.owners = owners
self.owners = data.get('owners', [])

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

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

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

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

self._fetch_roster(roster)
self._fetch_schedule(schedule)
self.owners = owners
self.owners = data.get('owners', [])

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

self._fetch_roster(roster, year)
self._fetch_schedule(schedule)
self.owners = owners
self.owners = data.get('owners', [])

def __repr__(self):
return f'Team({self.team_name})'
Expand Down
5 changes: 2 additions & 3 deletions tests/hockey/unit/test_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ 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, owners=self.owners)
team = Team(self.team, roster= self.team_roster, schedule= self.schedule, year= self.year)
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, owners=self.owners)
team = Team(self.team, roster= self.team_roster, schedule= self.schedule, year= self.year)

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

0 comments on commit 0aef069

Please sign in to comment.