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

Added League Function to get All Players #283

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

troylee24
Copy link

  • Changed the free_agents() function to a more general player() option that accepts a new parameter type 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.

@cwendt94
Copy link
Owner

@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.

@pete7863
Copy link
Contributor

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)?

@cwendt94
Copy link
Owner

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.

@Kjeldgaard
Copy link
Contributor

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?

@cwendt94
Copy link
Owner

@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
Copy link
Contributor

@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!

@cwendt94
Copy link
Owner

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.

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.

4 participants