ESPN Fantasy API请求过滤带有X-Fantasy-Filter标题



我正在使用requests从ESPN Fantasy API获取NBA球员统计数据。在下游,我正在建造熊猫df。我遇到的一件事是过滤JSON嵌套中更深的字段的请求。我可以在标题中筛选status并按PercOwned排序,但似乎无法筛选像statSplitTypeIdauctionValue这样的项目。有什么想法吗?

网址:https://fantasy.espn.com/apis/v3/games/fba/seasons/2022/segments/0/leagues/1747675438?view=kona_player_info

当前标题:

headers = {
'X-Fantasy-Filter': '{"players":
{"filterStatus":{"value":["FREEAGENT","WAIVERS","ONTEAM"]},
"sortPercOwned":{"sortAsc":false,"sortPriority":1}}}'
}

示例JSON响应

{
"players": [
{
"draftAuctionValue": 0,
"id": 3032977,
"keeperValue": 1,
"keeperValueFuture": 1,
"lineupLocked": false,
"onTeamId": 4,
"player": {
"active": true,
"defaultPositionId": 4,
"draftRanksByRankType": {
"STANDARD": {
"auctionValue": 64,
"published": false,
"rank": 2,
"rankSourceId": 0,
"rankType": "STANDARD",
"slotId": 0
}
},
"droppable": false,
"eligibleSlots": [
3,
6,
8,
9,
10,
11,
12,
13
],
"firstName": "Giannis",
"fullName": "Giannis Antetokounmpo",
"ownership": {
"activityLevel": null,
"auctionValueAverage": 64.22289156626506,
"auctionValueAverageChange": -2.9199655765920767,
"averageDraftPosition": 2.6674573758339513,
"averageDraftPositionPercentChange": -0.6431361088656256,
"date": 1637244022069,
"leagueType": 0,
"percentChange": -0.006086844650013745,
"percentOwned": 99.95081910133877,
"percentStarted": 85.24790654758796
},
},
"rosterLocked": true,
"status": "ONTEAM",
"tradeLocked": false```

您可以使用"filterStatsForSplitTypeIds":{"value":[1]}过滤statSplits,只需将id添加到值列表中。我不知道什么id对应什么split。

至于auctionValue,我找不到它在任何对api的请求中被实现。

import requests

headers = {
'X-Fantasy-Filter': '{"players":
{"filterStatus":{"value":["FREEAGENT","WAIVERS","ONTEAM"]},
"filterStatsForSplitTypeIds":{"value":[0,1,2]},
"sortPercOwned":{"sortAsc":false,"sortPriority":1}}}'
}
url = 'https://fantasy.espn.com/apis/v3/games/fba/seasons/2022/segments/0/leagues/1747675438?view=kona_player_info'
jsonData = requests.get(url, headers=headers).json()

最新更新