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

Restore owner and member references #491

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion espn_api/base_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def _fetch_teams(self, data, TeamClass, pro_schedule = None):
'''Fetch teams in league'''
self.teams = []
teams = data['teams']
members = data['members']
schedule = data['schedule']
seasonId = data['seasonId']

Expand All @@ -53,7 +54,14 @@ def _fetch_teams(self, data, TeamClass, pro_schedule = None):

for team in teams:
roster = team_roster[team['id']]
self.teams.append(TeamClass(team, roster=roster, schedule=schedule, year=seasonId, pro_schedule=pro_schedule))
for member in members:
# For league that is not full the team will not have a owner field
if 'owners' not in team or not team['owners']:
member = None
break
elif member['id'] == team['owners'][0]:
break
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
7 changes: 6 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, member, roster, schedule, year, **kwargs):
self.team_id = data['id']
self.team_abbrev = data['abbrev']
if year < 2023:
Expand All @@ -17,11 +17,16 @@ def __init__(self, data, roster, schedule, year, **kwargs):
self.wins = data['record']['overall']['wins']
self.losses = data['record']['overall']['losses']
self.ties = data['record']['overall']['ties']
self.owner = 'None'
self.logo_url = ''
self.standing = data['playoffSeed']
self.final_standing = data['rankCalculatedFinal']
self.roster = []
self.schedule = []

if member:
self.owner = "%s %s" % (member['firstName'],
member['lastName'])
if 'logo' in data:
self.logo_url = data['logo']

Expand Down
7 changes: 5 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, **kwargs):
def __init__(self, data, member, roster, schedule, year, **kwargs):
self.team_id = data['id']
self.team_abbrev = data['abbrev']
if year < 2023:
Expand All @@ -15,7 +15,8 @@ def __init__(self, data, roster, schedule, year, **kwargs):
self.division_name = '' # set by caller
self.wins = data['record']['overall']['wins']
self.losses = data['record']['overall']['losses']
self.ties = data['record']['overall']['ties']
self.ties = data['record']['overall']['ties']
self.owner = 'None'
self.logo_url = ''
self.stats = None
self.standing = data['playoffSeed']
Expand All @@ -25,6 +26,8 @@ def __init__(self, data, roster, schedule, year, **kwargs):

if 'valuesByStat' in data:
self.stats = {STATS_MAP.get(i, i): j for i, j in data['valuesByStat'].items()}
if member:
self.owner = f"{member['firstName']} {member['lastName']}"
if 'logo' in data:
self.logo_url = data['logo']

Expand Down
6 changes: 5 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, member, roster, schedule, year, **kwargs):
self.team_id = data['id']
self.team_abbrev = data['abbrev']
if year < 2023:
Expand All @@ -22,6 +22,10 @@ def __init__(self, data, roster, schedule, year, **kwargs):
self.trades = data.get('transactionCounter', {}).get('trades', 0)
self.playoff_pct = data.get('currentSimulationResults', {}).get('playoffPct', 0) * 100
self.draft_projected_rank = data.get('draftDayProjectedRank', 0)
self.owner = 'None'
if member:
self.owner = "%s %s" % (member['firstName'],
member['lastName'])
self.streak_length = data['record']['overall']['streakLength']
self.streak_type = data['record']['overall']['streakType']
self.standing = data['playoffSeed']
Expand Down
1 change: 1 addition & 0 deletions espn_api/hockey/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
]

from .league import League
from .member import Member
from .player import Player
from .record import Record
from .team import Team
Expand Down
8 changes: 8 additions & 0 deletions espn_api/hockey/member.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Member(object):

def __init__(self, data):
self.id = data['id']
self.display_name = data['displayName']
self.first_name = data['firstName']
self.last_name = data['lastName']
self.full_name = self.first_name + ' ' + self.last_name
5 changes: 4 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, member, roster, schedule, year, **kwargs):
self.team_id = data['id']
self.team_abbrev = data['abbrev']
if year < 2023:
Expand All @@ -29,6 +29,9 @@ def __init__(self, data, roster, schedule, year, **kwargs):

if 'valuesByStat' in data:
self.stats = {STATS_MAP[i]: j for i, j in data['valuesByStat'].items()}
if member:
self.owner = "%s %s" % (member['firstName'],
member['lastName'])
if 'logo' in data:
self.logo_url = data['logo']

Expand Down
4 changes: 3 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, member, roster, schedule, year, **kwargs):
self.team_id = data['id']
self.team_abbrev = data['abbrev']
if year < 2023:
Expand All @@ -26,6 +26,8 @@ def __init__(self, data, roster, schedule, year, **kwargs):

if 'valuesByStat' in data:
self.stats = {STATS_MAP[i]: j for i, j in data['valuesByStat'].items()}
if member:
self.owner = f"{member['firstName']} {member['lastName']}"
if 'logo' in data:
self.logo_url = data['logo']

Expand Down
4 changes: 2 additions & 2 deletions tests/hockey/unit/test_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def setUp(self) -> None:
self.team_roster = self.team['roster']

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, member= None, 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)
team = Team(self.team, roster= self.team_roster, member= None, schedule= self.schedule, year= self.year)

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