Closed bnm91 closed 8 months ago
I’ll take a look at these failures soon
Don't worry about the hockey team names one those just popped up, but it does look like two new ones are failing for owner
logic.
For what it's worth, there may have been further changes to the ESPN API this morning. I was making my own attempt at fixing this issue when the API call started returning additional fields under data['members']. Restoring the members/owner references from before commit cc82818 allows owner names to flow through again.
@cwendt94 I rewrote this to only include the "unique id" as you mentioned above. I also fixed a couple tests broken by these changes. I still think it would be nice to have the "member" (and therefore the user's actual name) associated with the Team but currently this leaves that exercise to the user. Perhaps I'll open a separate discussion for that improvement
I'm struggling to run the entire test suite in my environment but addressed a few test issues I was aware of.
The following tests will probably still fail but due to separate issue: test_league_draft (basketball.integration.test_league.LeagueTest) separate issue -- test uses 2019 data which requires 'location' but none exists
test_box_scores (football.integration.test_league.LeagueTest) separate issue -- test uses 2019 data which requires 'location' but none exists
test_league_int (hockey.integration.test_league.LeagueTest) separate issue -- test uses 2021 data which requires 'location' but none exists
All modified and coverable lines are covered by tests :white_check_mark:
Comparison is base (
f268c46
) 80.42% compared to head (ed238bc
) 80.53%. Report is 7 commits behind head on master.
:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@bnm91 Is there an endpoint / header we can use to get the actual users' names?
I'm using the following workaround for now:
def set_league_endpoint(league: League) -> None:
"""Set the league's endpoint."""
# Current season
if league.year >= (datetime.datetime.today() - datetime.timedelta(weeks=12)).year:
league.endpoint = (
"https://fantasy.espn.com/apis/v3/games/ffl/seasons/"
+ str(league.year)
+ "/segments/0/leagues/"
+ str(league.league_id)
+ "?"
)
# Old season
else:
league.endpoint = (
"https://fantasy.espn.com/apis/v3/games/ffl/leagueHistory/"
+ str(league.league_id)
+ "?seasonId="
+ str(league.year)
+ "&"
)
def set_owner_names(league: League):
"""This function sets the owner names for each team in the league.
The team.owners attribute only contains the SWIDs of each owner, not their real name.
Args:
league (League): ESPN League object
"""
endpoint = "{}view=mTeam".format(league.endpoint)
r = requests.get(endpoint, cookies=league.cookies).json()
if type(r) == list:
r = r[0]
# For each member in the data, create a map from SWID to their full name
swid_to_name = {}
for member in r["members"]:
swid_to_name[member["id"]] = re.sub(
" +", " ", member["firstName"] + " " + member["lastName"]
).title()
# Set the owner name for each team
for team in league.teams:
team.owner = swid_to_name[team.owners[0]]
set_league_endpoint(league)
set_owner_names(league)
Problem
Currently there's no way to get info on the "owner" (aka "manager") of a Team. While the team's name is available, those are subject to change making tracking over longer periods difficult
Solution
ESPN has a concept of Members on a League and Owners on a Team. These are tied together by an Id and the Member entity has much more stable information about the actual humans behind the team. Storing this Member info with the Team will make that info more accessible
Code Changes