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

bugfix/Fix multiple pro schedule requests #631

Conversation

JohnDiebold
Copy link
Contributor

When a league is initialized, a get_pro_schedule espn request is done. It's not stored though so when league.box_scores or league.player_info is called, it re-calls the pro schedule request.

This can be fixed by changing this line in the _fetch_teams function from:
pro_schedule = self._get_all_pro_schedule()
to:
self.pro_schedule = self._get_all_pro_schedule()

and then using self.pro_schedule in the other league functions box_Scores and player_info.

Take this basic program:

league = espn_api.basketball.League(...)
player = league.player_info(playerId=[4701230])
box = league.box_scores()

Currently this does the following api requests:

  1. ESPN API Request: url: https://lm-api-reads.fantasy.espn.com/apis/v3/games/fba/seasons/2025/segments/0/leagues/64732 params: {'view': ['mTeam', 'mRoster', 'mMatchup', 'mSettings', 'mStandings']} headers: None
  2. ESPN API Request: url: https://lm-api-reads.fantasy.espn.com/apis/v3/games/fba/seasons/2025/players params: {'view': 'players_wl'} headers: {'x-fantasy-filter': '{"filterActive": {"value": true}}'}
  3. ESPN API Request: url: https://lm-api-reads.fantasy.espn.com/apis/v3/games/fba/seasons/2025 params: {'view': 'proTeamSchedules_wl'} headers: None
  4. ESPN API Request: url: https://lm-api-reads.fantasy.espn.com/apis/v3/games/fba/seasons/2025/segments/0/leagues/64732 params: {'view': 'mDraftDetail'} headers: None
  5. ESPN API Request: url: https://lm-api-reads.fantasy.espn.com/apis/v3/games/fba/seasons/2025/segments/0/leagues/64732 params: {'view': 'kona_playercard'} headers: {'x-fantasy-filter': '{"players": {"filterIds": {"value": [4701230]}, "filterStatsForTopScoringPeriodIds": {"value": 146, "additionalValue": ["002025", "102025"]}}}'}
  6. ESPN API Request: url: https://lm-api-reads.fantasy.espn.com/apis/v3/games/fba/seasons/2025 params: {'view': 'proTeamSchedules_wl'} headers: None
  7. ESPN API Request: url: https://lm-api-reads.fantasy.espn.com/apis/v3/games/fba/seasons/2025/segments/0/leagues/64732 params: {'view': ['mMatchupScore', 'mScoreboard'], 'scoringPeriodId': 103} headers: {'x-fantasy-filter': '{"schedule": {"filterMatchupPeriodIds": {"value": [15]}}}'}
  8. ESPN API Request: url: https://lm-api-reads.fantasy.espn.com/apis/v3/games/fba/seasons/2025 params: {'view': 'proTeamSchedules_wl'} headers: None

Note the 3 pro schedule requests, #s 3, 6, 8.

With this fix the same program only does the pro schedule request once, when the league is initialized:

  1. ESPN API Request: url: https://lm-api-reads.fantasy.espn.com/apis/v3/games/fba/seasons/2025/segments/0/leagues/64732 params: {'view': ['mTeam', 'mRoster', 'mMatchup', 'mSettings', 'mStandings']} headers: None
  2. ESPN API Request: url: https://lm-api-reads.fantasy.espn.com/apis/v3/games/fba/seasons/2025/players params: {'view': 'players_wl'} headers: {'x-fantasy-filter': '{"filterActive": {"value": true}}'}
  3. ESPN API Request: url: https://lm-api-reads.fantasy.espn.com/apis/v3/games/fba/seasons/2025 params: {'view': 'proTeamSchedules_wl'} headers: None
  4. ESPN API Request: url: https://lm-api-reads.fantasy.espn.com/apis/v3/games/fba/seasons/2025/segments/0/leagues/64732 params: {'view': 'mDraftDetail'} headers: None
  5. ESPN API Request: url: https://lm-api-reads.fantasy.espn.com/apis/v3/games/fba/seasons/2025/segments/0/leagues/64732 params: {'view': 'kona_playercard'} headers: {'x-fantasy-filter': '{"players": {"filterIds": {"value": [4701230]}, "filterStatsForTopScoringPeriodIds": {"value": 146, "additionalValue": ["002025", "102025"]}}}'}
  6. ESPN API Request: url: https://lm-api-reads.fantasy.espn.com/apis/v3/games/fba/seasons/2025/segments/0/leagues/64732 params: {'view': ['mMatchupScore', 'mScoreboard'], 'scoringPeriodId': 103} headers: {'x-fantasy-filter': '{"schedule": {"filterMatchupPeriodIds": {"value": [15]}}}'}

Copy link

codecov bot commented Feb 1, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 82.70%. Comparing base (805ba67) to head (543309c).
Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
espn_api/basketball/league.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #631      +/-   ##
==========================================
- Coverage   82.71%   82.70%   -0.02%     
==========================================
  Files          61       61              
  Lines        2326     2324       -2     
==========================================
- Hits         1924     1922       -2     
  Misses        402      402              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Owner

@cwendt94 cwendt94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this! This is a great improvement.

I think this can be expanded even further and make this call and set this var at the base_league level so that all sports can take advantage of this. I can look at that and adding this improvement to all sports!

@cwendt94
Copy link
Owner

cwendt94 commented Feb 6, 2025

Just need to resolve conflict and I can merge it in!

@JohnDiebold
Copy link
Contributor Author

Resolved, thanks!

@cwendt94 cwendt94 merged commit 9c0f586 into cwendt94:master Feb 7, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants