cwendt94 / espn-api

ESPN Fantasy API! (Football, Basketball)
MIT License
550 stars 184 forks source link

Players not found using League.player_info #223

Closed drewski3420 closed 2 years ago

drewski3420 commented 2 years ago

Sport

Football

Summary

Trying to get the Pro Team and Position for previous year's draft picks. These properties aren't members of the Pick class, so I'm calling the League.player_info() method and passing in the player name.

This works for some players (works for Austin Ekeler, Amari Cooper) but fails for other players (fails on A.J. Green). No error message is displayed but the API returns an empty {} for these players.

Here is the debug response for AJ Green. I have attached the full debug dump as well: ESPN API Request: url: https://fantasy.espn.com/apis/v3/games/ffl/seasons/2020/segments/0/leagues/376 params: {'view': 'kona_playercard'} headers: {'x-fantasy-filter': '{"players": {"filterIds": {"value": [4038437]}, "filterStatsForTopScoringPeriodIds": {"value": 16, "additionalValue": ["002020", "102020"]}}}'} ESPN API Response: {'players': []}

Logs/Data

[Uploading 123.log…]()

drewski3420 commented 2 years ago

Er, I suppose this can be closed. Passing in player ID instead of name is working fine.

cwendt94 commented 2 years ago

The name should map to the same player id that you pass in. Does it look like the same call to the api as player id when you pass player name?

drewski3420 commented 2 years ago

I tried 3 player_info calls. 1 works, 2 and 3 fail

  1. player_by_id = league.player_info(playerId = pick.playerId) #player ID, named parameter
  2. player_by_name_param = league.player_info(name=pick.playerName) #player Name, named parameter
  3. player_by_name_no_param = league.player_info(pick.playerName) #player Name, no named parameter

When I look at the calls, the ones that fail show a different playerId in the header of the request. Working request has the correct ID 13983 vs 4038437 on the ones that fail

ESPN API Request: url: https://fantasy.espn.com/apis/v3/games/ffl/seasons/2020/segments/0/leagues/XXX params: {'view': 'kona_playercard'} headers: {'x-fantasy-filter': '{"players": {"filterIds": {"value": [13983]}, "filterStatsForTopScoringPeriodIds": {"value": 16, "additionalValue": ["002020", "102020"]}}}'}

ESPN API Request: url: https://fantasy.espn.com/apis/v3/games/ffl/seasons/2020/segments/0/leagues/XXX params: {'view': 'kona_playercard'} headers: {'x-fantasy-filter': '{"players": {"filterIds": {"value": [4038437]}, "filterStatsForTopScoringPeriodIds": {"value": 16, "additionalValue": ["002020", "102020"]}}}'}

cwendt94 commented 2 years ago

Thanks for testing it out and looking at the calls! I will look into it. I wonder if there are multiple players with that same name. It's definitely best bet to use player id as it is unique for every player.

kmcentush commented 2 years ago

@cwendt94 is there a way to get multiple player infos at once? I tried playing with the value field in filters = {'players':{'filterIds':{'value':[playerId]}, 'filterStatsForTopScoringPeriodIds':{'value':17, "additionalValue":["00{}".format(self.year), "10{}".format(self.year)]}}} by putting a list of multiple player IDs instead of a list of just one ID, but the API is just returning a single player. I presume this is an ESPN limitation.

My overall goal is to get the player info (stats, etc.) for every player. Right now it seems like I'll have to run individual requests for all players. Is this the case?

cwendt94 commented 2 years ago

@kmcentush yes I will just need to update the player_info function to account for the playerId variable to be a list. The API call allows for multiple ids. If multiple ids are passed the response will be an array of players instead of just a singe player class.

Should have it done sometime tomorrow.

kmcentush commented 2 years ago

@cwendt94 Great! Thanks for your work on this awesome library.

cwendt94 commented 2 years ago

@kmcentush feature now in package v0.20.0. You can now pass in a list of ids with playerId field. The function will return a list of players

def player_info(name: str = None, playerId: Union[int, list] = None) -> -> Union[Player, List[Player]]: