cwendt94 / espn-api

ESPN Fantasy API! (Football, Basketball)
MIT License
613 stars 198 forks source link

KeyError: 'home' while loading Points-Based League #189

Open ebjaime opened 3 years ago

ebjaime commented 3 years ago

While fetching the league (in _fetch_league ) a _map_matchup_ids method is called where a key error is encountered:

File ".../espn_api/basketball/league.py", line 36, in _map_matchup_ids
    scoring_periods = match['home'].get('pointsByScoringPeriod', {}).keys()

KeyError: 'home' 

For public leagues, this error does not show up. I can't seem to figure out why this happens...

cwendt94 commented 3 years ago

That's strange its only erroring for private leagues. What is the scoring settings for the private league? I will add a check that home is present so it doesn't error

ebjaime commented 3 years ago

My bad. It's a points league. I was confusing the team variables for NBA teams instead of fantasy teams. I had it all wrong.

I tried adding a check statement for the home parameter in line 36 at league.py but a different error occured regarding that same parameter. It might also be related to the fact that it is a points-league.

Still, isn't there an option to use the API for points-based leagues? If not, I may be able to extend the API (or assist in the process) for it to work for points leagues.

(I'm sorry for my ignorance of the API, I haven't had time to dig deep into the code.)

cwendt94 commented 3 years ago

Is it a total season points league?

The majority of the API the scoring settings will not effect it. The only interface that it gets tricky is the box_scores and the corresponding box_player object.

Fantasy basketball is still relatively new for me and I have only played in H2H Points league. Its interesting how much the scoring settings vary in basketball.

ebjaime commented 3 years ago

It is a total season points league indeed.

A workaround to solve the home issue is commenting out the call to the self._map_matchup_ids() in self._fetch_league(). As you said the box_scores and box_players methods throw errors when calling them (because of not initialized h2h parameters). But the rest of the API seems to work just fine...

An extension for the API to get in the future could include similar functionalities for points leagues (get previous scoring period data). As I said, I am available and would be happy to assist in the process.

cwendt94 commented 3 years ago

This PR #192 should hopefully fix the error when initializing the League.

Yeah that sounds like a great idea and would be very useful for some of the other basketball scoring settings as well. Your help would be greatly appreciated, I can always use more contributors!

ebjaime commented 3 years ago

Great! Just saw it.

I'll add a pull request with support for points-leagues as soon as I can.

I'll leave the issue open until then. Cheers!

cwendt94 commented 3 years ago

Sounds good! Thanks again for looking into this issue and helping out!