-
Notifications
You must be signed in to change notification settings - Fork 224
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
Conversation
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 |
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'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_box_scores (football.integration.test_league.LeagueTest) test_league_int (hockey.integration.test_league.LeagueTest) |
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #487 +/- ##
==========================================
+ Coverage 80.42% 80.53% +0.11%
==========================================
Files 59 59
Lines 2094 2106 +12
==========================================
+ Hits 1684 1696 +12
Misses 410 410
☔ View full report in Codecov by Sentry. |
@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