espn-api
espn-api copied to clipboard
Added League Function to get All Players
- Changed the
free_agents()
function to a more generalplayer()
option that accepts a new parametertype
to define what kind of players a user wants to fetch (i.e. "FREEAGENT", "WAIVERS", "ONTEAM") - New tests added for
player()
function
Note: I noticed that when creating the Player()
object, it omits the onTeamId
. It may be useful to retain that information so that one could go from Player
to Team
.
@troylee24 thanks for the PR, I like the idea! free_agents
is one of the functions I want to move to the base league because the logic is the same across all sports.
I plan on doing a large refactor in the next couple months which is going to be part of this package going to v1.0.0
. I am going to make a feature branch for all of this work and I think this would be a good PR against that. I don't want to make any big changes to the package while we are in the middle of the season.
Is this still planned for integration prior to the 2022 football season start? I think this is a really nice change to allow fetching all players. Perhaps a set of wrapper helper functions could be created to grab subsets of the player types and maintain the existing function name (free_agents wraps the player function with the type specified)?
Thanks @pete7863 for bringing this to my attention. I will relook at this in the next couple days!
The player_info functionality recently got updated to take a list of playerIds which then can allow you to get as any players information needed in one call.
The player_info functionality recently got updated to take a list of playerIds which then can allow you to get as any players information needed in one call.
I'm trying to get player data for all players. I'm using the playerId's from player_map. However, it fails with "header too long". Can you get player data for all players in one call? If so, can you share how you do it.
Second, did you also add onTeamId
to the Player
object?
@Kjeldgaard For right now to get around that you can make a couple calls with the player_info and see if you can do half the players in the player_map.
@Kjeldgaard For right now to get around that you can make a couple calls with the player_info and see if you can do half the players in the player_map.
I did as follows to get all playerIds:
from espn_api.requests import EspnFantasyRequests
...
espn_request = EspnFantasyRequests(sport='nfl', year=year, league_id=league_id, cookies=cookies)
pro_players = espn_request.get_pro_players()
pro_players
includes all playerIds.
Previously, I called player_info()
for each player, now I'm calling player_info()
with 1000 playerIds, Getting all player data went from 25 minutes to 7 seconds on a ARM Ampere A1 (Oracle cloud free tier) :)
Thanks for making this possible, it has taken my NFL fantasy game to a new level!
Thats great! I have been wanting to document the EspnFantasyRequests module for people that would like to get the raw data or just try out different ESPN calls.
Just a FYI, you can also access the ESPN request in your league like this league.espn_request.get_pro_players()
so you don't have to initialize it with the sport, league, and credentials.