Comments (13)
Hmm that’s a great question. That wouldn’t be a bad idea but holding all players could take up a lot of space.
So if you are looking for players that were picked up we know they belong to a team. We might be able to use the same endpoint as free_agents function but filter on owned players instead of wavier/free agents.
from espn-api.
from espn-api.
That’s a good point, I didn’t even think about dropped players. It definitely adds some more complexity. I wonder if ESPN has a endpoint where you could just call for one player’s data or something like that
from espn-api.
You could get week-by-week box_scores, which would give you points that a player earned while on a team, but it would miss points (not) accrued in free-agency.
from espn-api.
Looks like you can use the free_agent request and slightly change the filters. The Player object that comes back shows the last 2 week's scores. It also shows total season points. However, it's a bit strange to make out.
See below example for Christian McCaffery
params = {
'scoringPeriodId': 5,
'view': 'kona_player_info',
}
filters = {"players":{"filterIds":{"value":[3117251]},"sortPercOwned":{"sortPriority":2,"sortAsc":False},"filterStatsForTopScoringPeriodIds":{"value":2,"additionalValue":["002019","102019","002018","1120195","022019"]}}}
headers = {'x-fantasy-filter': json.dumps(filters)}
r = requests.get(ENDPOINT, params=params, cookies=cookies, headers=headers)
- notice the filter is 'filterIds' for the player's ID
- Oh, as I'm typing this, I see 'filterStatsForTopScoringPeriods' is set to 2...wonder what happens if I up it? And the 'additional values' might be the answer to my question below..
- Season Total = 115
- Last week = 34.9
- 2 weeks ago = 30.8
- ...What is all that other stuff though? and the why the 2018 data?
Looks like...
- 002019 = '00' plus year. The 00 = Season Total
- 20195 = Year + "5" = Season Average points per week
from espn-api.
Nice, I was thinking you could probably pass in just a player id and players specific information. For the 2018 stats ESPN likes to show the previous season stats like points and rank
from espn-api.
Here's what I put together for fetching player_points. Can prob be cleaned up a bit, but it works. I stuck it in Player Object b/c I wasn't sure how else to utilize it inside the Player Object...
def fetch_player_points(self, playerId: int):
"""Retrieves a player's points"""
params = {
'scoringPeriodId': 5,
'view': 'kona_player_info',
}
filters = {"players": {
"filterIds": {"value": [playerId]},
"sortPercOwned": {"sortPriority": 2, "sortAsc": False},
"filterStatsForTopScoringPeriodIds": {"value": 3,
"additionalValue": ["002019", "102019", "002018", "1120195",
"022019"]}}}
headers = {'x-fantasy-filter': json.dumps(filters)}
r = requests.get(self.ENDPOINT, params=params, cookies=self.cookies, headers=headers)
data = r.json()
stats = data['players'][0]['player']['stats']
player_points = {}
for stat in stats:
if stat['id'] == str('00') + str(self.year):
player_points['points_season_total'] = stat['appliedTotal']
player_points['points_season_average'] = stat['appliedAverage']
if stat['id'] == str('00') + str(self.year-1):
player_points['points_season_last'] = stat['appliedTotal']
if stat['scoringPeriodId'] == self.current_week:
player_points['points_week_current'] = stat['appliedTotal']
if stat['scoringPeriodId'] == self.current_week - 1:
player_points['points_week_last'] = stat['appliedTotal']
return player_points
from espn-api.
So back to the title of the Topic -- I wonder how we can get the Player Object into he Recent Activity?
from espn-api.
Does that endpoint return the correct data to create a player object with it? Because if so what we could do is put this function in the League object and pass the function to the activity object to call it with the player ids to create a player
from espn-api.
great question and idea... (I couldn't figure out how to put the function in the league and pass it across :( )
I think most of the attributes in player object should be included in this endpoint. would need to do a little more digging, but certainly seems like it.
I had it run inside the player object when the league was initializing...pretty slow, but cool to have the data.
from espn-api.
If you look at recent_activity function and the Activity class I pass get_team_data function so I can add the Team class. I was thinking you could do the same thing with a “get_player_function” pass that in and it will create a player object off of the player id
from espn-api.
@rysull23 Thanks for bringing this back up this year and showing your example code in #133! This is now in package version v0.8.0 🎉
from espn-api.
Welcome. Wow. Forgot about this. Lots of detail here. Thanks for incorporating.
The other piece of this which I spent a ton of time on was figuring out how to get more stat info out of that free_agent api. it's a bit cryptic, but I came close.
from espn-api.
Related Issues (20)
- Unable to access league data for 2018 season HOT 1
- Teams' names not updated HOT 1
- League current_week field returns 0 HOT 8
- meaning of statistics keys HOT 3
- Fix Team Data Change Working? HOT 1
- Add Owner info to Team
- Pulling League Data Errors in new season 23-24 HOT 1
- 'location' in data json doesn't exist anymore. Fix is provided HOT 2
- ESPN API Updated Key Names for Team Name HOT 1
- KeyError: 'location' in Fantasy BBall H2H Categories HOT 2
- Add back functionality to pull owner names HOT 4
- Getting "json.decoder.JSONDecodeError: Unterminated string" starting after NFL week 6 HOT 4
- Add accepted trade activity to fantasy basketball activity list HOT 3
- Player/Pick projected bid amount HOT 5
- slot_position only returning "PG" HOT 1
- Unable to get projected score of games of final completed week of season HOT 1
- Issue with Add full owner info to team commit HOT 2
- League.previousSeasons no longer an attribute? HOT 2
- Key Error when loading League HOT 2
- Lineups are only populating for first and current week matchups HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from espn-api.