cwendt94 / espn-api

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

statId lookup #84

Closed OD1995 closed 1 year ago

OD1995 commented 4 years ago

This is more of an ESPN API question than an issue with your (very useful) package. But I believe getting an answer should be useful for potential further/future development of the package.

I'm looking to extract the scoring settings of my league. This can be done as follows:

ENDPOINT = f"https://fantasy.espn.com/apis/v3/games/FFL/seasons/{year}/segments/0/leagues/{leagueID}"
cookies = {'espn_s2': espn_s2,
                'SWID': swid}
params = {'view': 'mSettings'}
r = requests.get(ENDPOINT, params=params, cookies=cookies)
data = r.json()
scoringFormat = data['settings']['scoringSettings']['scoringItems']

scoringFormat is now a list, where each element looks roughly like this:

{'isReverseItem': False,
 'leagueRanking': 0.0,
 'leagueTotal': 0.0,
 'points': -0.5,
 'statId': 85}

This statId comes up in other parts of API too, but I have found no way of matching it to an actual metric, aside from going through manually and working it out based on my league's settings. scoringFormat is 47 elements long in my league and I'd like to be able to apply this to other leagues with different scoring format variations, so I'd prefer not to take the manual route.

Is there any way of retrieving some sort of lookup for this?

joelataccelm commented 3 years ago

@OD1995 did you have any luck with this?

joelataccelm commented 3 years ago
[{
    "id": 0,
    "abbr": "PA",
    "label": "Each Pass Attempted"
}, {
    "id": 1,
    "abbr": "PC",
    "label": "Each Pass Completed"
}, {
    "id": 2,
    "abbr": "INC",
    "label": "Each Incomplete Pass"
}, {
    "id": 3,
    "abbr": "PY",
    "label": "Passing Yards"
}, {
    "id": 4,
    "abbr": "PTD",
    "label": "TD Pass"
}, {
    "id": 5,
    "abbr": "PY5",
    "label": "Every 5 passing yards"
}, {
    "id": 6,
    "abbr": "PY10",
    "label": "Every 10 passing yards"
}, {
    "id": 7,
    "abbr": "PY20",
    "label": "Every 20 passing yards "
}, {
    "id": 8,
    "abbr": "PY25",
    "label": "Every 25 passing yards "
}, {
    "id": 9,
    "abbr": "PY50",
    "label": "Every 50 passing yards"
}, {
    "id": 10,
    "abbr": "PY100",
    "label": "Every 100 passing yards"
}, {
    "id": 11,
    "abbr": "PC5",
    "label": "Every 5 pass completions"
}, {
    "id": 12,
    "abbr": "PC10",
    "label": "Every 10 pass completions"
}, {
    "id": 13,
    "abbr": "IP5",
    "label": "Every 5 pass incompletions"
}, {
    "id": 14,
    "abbr": "IP10",
    "label": "Every 10 pass incompletions"
}, {
    "id": 15,
    "abbr": "PTD40",
    "label": "40+ yard TD pass bonus"
}, {
    "id": 16,
    "abbr": "PTD50",
    "label": "50+ yard TD pass bonus"
}, {
    "id": 17,
    "abbr": "P300",
    "label": "300-399 yard passing game"
}, {
    "id": 18,
    "abbr": "P400",
    "label": "400+ yard passing game"
}, {
    "id": 19,
    "abbr": "2PC",
    "label": "2pt Passing Conversion"
}, {
    "id": 20,
    "abbr": "INTT",
    "label": "Interceptions Thrown"
}, {
    "id": 21,
    "abbr": "CPCT",
    "label": "Passing Completion Pct"
}, {
    "id": 22,
    "abbr": "PYPG",
    "label": "Passing Yards Per Game"
}, {
    "id": 23,
    "abbr": "RA",
    "label": "Rushing Attempts"
}, {
    "id": 24,
    "abbr": "RY",
    "label": "Rushing Yards"
}, {
    "id": 25,
    "abbr": "RTD",
    "label": "TD Rush"
}, {
    "id": 26,
    "abbr": "2PR",
    "label": "2pt Rushing Conversion"
}, {
    "id": 27,
    "abbr": "RY5",
    "label": "Every 5 rushing yards"
}, {
    "id": 28,
    "abbr": "RY10",
    "label": "Every 10 rushing yards"
}, {
    "id": 29,
    "abbr": "RY20",
    "label": "Every 20 rushing yards"
}, {
    "id": 30,
    "abbr": "RY25",
    "label": "Every 25 rushing yards "
}, {
    "id": 31,
    "abbr": "RY50",
    "label": "Every 50 rushing yards"
}, {
    "id": 32,
    "abbr": "R100",
    "label": "Every 100 rushing yards"
}, {
    "id": 33,
    "abbr": "RA5",
    "label": "Every 5 rush attempts"
}, {
    "id": 34,
    "abbr": "RA10",
    "label": "Every 10 rush attempts"
}, {
    "id": 35,
    "abbr": "RTD40",
    "label": "40+ yard TD rush bonus"
}, {
    "id": 36,
    "abbr": "RTD50",
    "label": "50+ yard TD rush bonus"
}, {
    "id": 37,
    "abbr": "RY100",
    "label": "100-199 yard rushing game"
}, {
    "id": 38,
    "abbr": "RY200",
    "label": "200+ yard rushing game"
}, {
    "id": 39,
    "abbr": "RYPA",
    "label": "Rushing Yards Per Attempt"
}, {
    "id": 40,
    "abbr": "RYPG",
    "label": "Rushing Yards Per Game"
}, {
    "id": 41,
    "abbr": "RECS",
    "label": "Receptions"
}, {
    "id": 42,
    "abbr": "REY",
    "label": "Receiving Yards"
}, {
    "id": 43,
    "abbr": "RETD",
    "label": "TD Reception"
}, {
    "id": 44,
    "abbr": "2PRE",
    "label": "2pt Receiving Conversion"
}, {
    "id": 45,
    "abbr": "RETD40",
    "label": "40+ yard TD rec bonus"
}, {
    "id": 46,
    "abbr": "RETD50",
    "label": "50+ yard TD rec bonus"
}, {
    "id": 47,
    "abbr": "REY5",
    "label": "Every 5 receiving yards"
}, {
    "id": 48,
    "abbr": "REY10",
    "label": "Every 10 receiving yards"
}, {
    "id": 49,
    "abbr": "REY20",
    "label": "Every 20 receiving yards"
}, {
    "id": 50,
    "abbr": "REY25",
    "label": "Every 25 receiving yards"
}, {
    "id": 51,
    "abbr": "REY50",
    "label": "Every 50 receiving yards"
}, {
    "id": 52,
    "abbr": "RE100",
    "label": "Every 100 receiving yards"
}, {
    "id": 53,
    "abbr": "REC",
    "label": "Each reception"
}, {
    "id": 54,
    "abbr": "REC5",
    "label": "Every 5 receptions"
}, {
    "id": 55,
    "abbr": "REC10",
    "label": "Every 10 receptions"
}, {
    "id": 56,
    "abbr": "REY100",
    "label": "100-199 yard receiving game"
}, {
    "id": 57,
    "abbr": "REY200",
    "label": "200+ yard receiving game"
}, {
    "id": 58,
    "abbr": "RET",
    "label": "Receiving Target"
}, {
    "id": 59,
    "abbr": "YAC",
    "label": "Receiving Yards After Catch"
}, {
    "id": 60,
    "abbr": "YPC",
    "label": "Receiving Yards Per Catch"
}, {
    "id": 61,
    "abbr": "REYPG",
    "label": "Receiving Yards Per Game"
}, {
    "id": 62,
    "abbr": "PTL",
    "label": "Total 2pt Conversions"
}, {
    "id": 63,
    "abbr": "FTD",
    "label": "Fumble Recovered for TD"
}, {
    "id": 64,
    "abbr": "SKD",
    "label": "Sacked"
}, {
    "id": 65,
    "abbr": "PFUM",
    "label": "Passing Fumbles"
}, {
    "id": 66,
    "abbr": "RFUM",
    "label": "Rushing Fumbles"
}, {
    "id": 67,
    "abbr": "REFUM",
    "label": "Receiving Fumbles"
}, {
    "id": 68,
    "abbr": "FUM",
    "label": "Total Fumbles"
}, {
    "id": 69,
    "abbr": "PFUML",
    "label": "Passing Fumbles Lost"
}, {
    "id": 70,
    "abbr": "RFUML",
    "label": "Rushing Fumbles Lost"
}, {
    "id": 71,
    "abbr": "REFUML",
    "label": "Receiving Fumbles Lost"
}, {
    "id": 72,
    "abbr": "FUML",
    "label": "Total Fumbles Lost"
}, {
    "id": 73,
    "abbr": "TT",
    "label": "Total Turnovers"
}, {
    "id": 74,
    "abbr": "FG50P",
    "label": "FG Made (50+ yards)"
}, {
    "id": 75,
    "abbr": "FGA50P",
    "label": "FG Attempted (50+ yards)"
}, {
    "id": 76,
    "abbr": "FGM50P",
    "label": "FG Missed (50+ yards)"
}, {
    "id": 77,
    "abbr": "FG40",
    "label": "FG Made (40-49 yards)"
}, {
    "id": 78,
    "abbr": "FGA40",
    "label": "FG Attempted (40-49 yards)"
}, {
    "id": 79,
    "abbr": "FGM40",
    "label": "FG Missed (40-49 yards)"
}, {
    "id": 80,
    "abbr": "FG0",
    "label": "FG Made (0-39 yards)"
}, {
    "id": 81,
    "abbr": "FGA0",
    "label": "FG Attempted (0-39 yards)"
}, {
    "id": 82,
    "abbr": "FGM0",
    "label": "FG Missed (0-39 yards)"
}, {
    "id": 83,
    "abbr": "FG",
    "label": "Total FG Made"
}, {
    "id": 84,
    "abbr": "FGA",
    "label": "Total FG Attempted"
}, {
    "id": 85,
    "abbr": "FGM",
    "label": "Total FG Missed"
}, {
    "id": 86,
    "abbr": "PAT",
    "label": "Each PAT Made"
}, {
    "id": 87,
    "abbr": "PATA",
    "label": "Each PAT Attempted"
}, {
    "id": 88,
    "abbr": "PATM",
    "label": "Each PAT Missed"
}, {
    "id": 89,
    "abbr": "PA0",
    "label": "0 points allowed"
}, {
    "id": 90,
    "abbr": "PA1",
    "label": "1-6 points allowed"
}, {
    "id": 91,
    "abbr": "PA7",
    "label": "7-13 points allowed"
}, {
    "id": 92,
    "abbr": "PA14",
    "label": "14-17 points allowed"
}, {
    "id": 93,
    "abbr": "BLKKRTD",
    "label": "Blocked Punt or FG return for TD"
}, {
    "id": 94,
    "abbr": "DEFRETTD",
    "label": "Fumble or INT Return for TD"
}, {
    "id": 95,
    "abbr": "INT",
    "label": "Each Interception"
}, {
    "id": 96,
    "abbr": "FR",
    "label": "Each Fumble Recovered"
}, {
    "id": 97,
    "abbr": "BLKK",
    "label": "Blocked Punt, PAT or FG"
}, {
    "id": 98,
    "abbr": "SF",
    "label": "Each Safety"
}, {
    "id": 99,
    "abbr": "SK",
    "label": "Each Sack"
}, {
    "id": 100,
    "abbr": "HALFSK",
    "label": "1/2 Sack"
}, {
    "id": 101,
    "abbr": "KRTD",
    "label": "Kickoff Return TD"
}, {
    "id": 102,
    "abbr": "PRTD",
    "label": "Punt Return TD"
}, {
    "id": 103,
    "abbr": "INTTD",
    "label": "Interception Return TD"
}, {
    "id": 104,
    "abbr": "FRTD",
    "label": "Fumble Return TD"
}, {
    "id": 105,
    "abbr": "TRTD",
    "label": "Total Return TD"
}, {
    "id": 106,
    "abbr": "FF",
    "label": "Each Fumble Forced"
}, {
    "id": 107,
    "abbr": "TKA",
    "label": "Assisted Tackles"
}, {
    "id": 108,
    "abbr": "TKS",
    "label": "Solo Tackles"
}, {
    "id": 109,
    "abbr": "TK",
    "label": "Total Tackles"
}, {
    "id": 110,
    "abbr": "TK3",
    "label": "Every 3 Total Tackles"
}, {
    "id": 111,
    "abbr": "TK5",
    "label": "Every 5 Total Tackles"
}, {
    "id": 112,
    "abbr": "STF",
    "label": "Stuffs"
}, {
    "id": 113,
    "abbr": "PD",
    "label": "Passes Defensed"
}, {
    "id": 114,
    "abbr": "KR",
    "label": "Kickoff Return Yards"
}, {
    "id": 115,
    "abbr": "PR",
    "label": "Punt Return Yards"
}, {
    "id": 116,
    "abbr": "KR10",
    "label": "Every 10 kickoff return yards"
}, {
    "id": 117,
    "abbr": "KR25",
    "label": "Every 25 kickoff return yards"
}, {
    "id": 118,
    "abbr": "PR10",
    "label": "Every 10 punt return yards"
}, {
    "id": 119,
    "abbr": "PR25",
    "label": "Every 25 punt return yards"
}, {
    "id": 120,
    "abbr": "PTSA",
    "label": "Points Allowed"
}, {
    "id": 121,
    "abbr": "PA18",
    "label": "18-21 points allowed"
}, {
    "id": 122,
    "abbr": "PA22",
    "label": "22-27 points allowed"
}, {
    "id": 123,
    "abbr": "PA28",
    "label": "28-34 points allowed"
}, {
    "id": 124,
    "abbr": "PA35",
    "label": "35-45 points allowed"
}, {
    "id": 125,
    "abbr": "PA46",
    "label": "46+ points allowed"
}, {
    "id": 126,
    "abbr": "PAPG",
    "label": "Points Allowed Per Game"
}, {
    "id": 127,
    "abbr": "YA",
    "label": "Yards Allowed"
}, {
    "id": 128,
    "abbr": "YA100",
    "label": "Less than 100 total yards allowed"
}, {
    "id": 129,
    "abbr": "YA199",
    "label": "100-199 total yards allowed"
}, {
    "id": 130,
    "abbr": "YA299",
    "label": "200-299 total yards allowed"
}, {
    "id": 131,
    "abbr": "YA349",
    "label": "300-349 total yards allowed"
}, {
    "id": 132,
    "abbr": "YA399",
    "label": "350-399 total yards allowed"
}, {
    "id": 133,
    "abbr": "YA449",
    "label": "400-449 total yards allowed"
}, {
    "id": 134,
    "abbr": "YA499",
    "label": "450-499 total yards allowed"
}, {
    "id": 135,
    "abbr": "YA549",
    "label": "500-549 total yards allowed"
}, {
    "id": 136,
    "abbr": "YA550",
    "label": "550+ total yards allowed"
}, {
    "id": 137,
    "abbr": "YAPG",
    "label": "Yards Allowed Per Game"
}, {
    "id": 138,
    "abbr": "PT",
    "label": "Net Punts"
}, {
    "id": 139,
    "abbr": "PTY",
    "label": "Punt Yards"
}, {
    "id": 140,
    "abbr": "PT10",
    "label": "Punts Inside the 10"
}, {
    "id": 141,
    "abbr": "PT20",
    "label": "Punts Inside the 20"
}, {
    "id": 142,
    "abbr": "PTB",
    "label": "Blocked Punts"
}, {
    "id": 143,
    "abbr": "PTR",
    "label": "Punts Returned"
}, {
    "id": 144,
    "abbr": "PTRY",
    "label": "Punt Return Yards"
}, {
    "id": 145,
    "abbr": "PTTB",
    "label": "Touchbacks"
}, {
    "id": 146,
    "abbr": "PTFC",
    "label": "Fair Catches"
}, {
    "id": 147,
    "abbr": "PTAVG",
    "label": "Punt Average"
}, {
    "id": 148,
    "abbr": "PTA44",
    "label": "Punt Average 44.0+"
}, {
    "id": 149,
    "abbr": "PTA42",
    "label": "Punt Average 42.0-43.9"
}, {
    "id": 150,
    "abbr": "PTA40",
    "label": "Punt Average 40.0-41.9"
}, {
    "id": 151,
    "abbr": "PTA38",
    "label": "Punt Average 38.0-39.9"
}, {
    "id": 152,
    "abbr": "PTA36",
    "label": "Punt Average 36.0-37.9"
}, {
    "id": 153,
    "abbr": "PTA34",
    "label": "Punt Average 34.0-35.9"
}, {
    "id": 154,
    "abbr": "PTA33",
    "label": "Punt Average 33.9 or less"
}, {
    "id": 155,
    "abbr": "TW",
    "label": "Team Win"
}, {
    "id": 156,
    "abbr": "TL",
    "label": "Team Loss"
}, {
    "id": 157,
    "abbr": "TIE",
    "label": "Team Tie"
}, {
    "id": 158,
    "abbr": "PTS",
    "label": "Points Scored"
}, {
    "id": 159,
    "abbr": "PPG",
    "label": "Points Scored Per Game"
}, {
    "id": 160,
    "abbr": "MGN",
    "label": "Margin of Victory"
}, {
    "id": 161,
    "abbr": "WM25",
    "label": "25+ point Win Margin"
}, {
    "id": 162,
    "abbr": "WM20",
    "label": "20-24 point Win Margin"
}, {
    "id": 163,
    "abbr": "WM15",
    "label": "15-19 point Win Margin"
}, {
    "id": 164,
    "abbr": "WM10",
    "label": "10-14 point Win Margin"
}, {
    "id": 165,
    "abbr": "WM5",
    "label": "5-9 point Win Margin"
}, {
    "id": 166,
    "abbr": "WM1",
    "label": "1-4 point Win Margin"
}, {
    "id": 167,
    "abbr": "LM1",
    "label": "1-4 point Loss Margin"
}, {
    "id": 168,
    "abbr": "LM5",
    "label": "5-9 point Loss Margin"
}, {
    "id": 169,
    "abbr": "LM10",
    "label": "10-14 point Loss Margin"
}, {
    "id": 170,
    "abbr": "LM15",
    "label": "15-19 point Loss Margin"
}, {
    "id": 171,
    "abbr": "LM20",
    "label": "20-24 point Loss Margin"
}, {
    "id": 172,
    "abbr": "LM25",
    "label": "25+ point Loss Margin"
}, {
    "id": 173,
    "abbr": "MGNPG",
    "label": "Margin of Victory Per Game"
}, {
    "id": 174,
    "abbr": "WINPCT",
    "label": "Winning Pct"
}, {
    "id": 175,
    "abbr": "PTD0",
    "label": "0-9 yd TD pass bonus"
}, {
    "id": 176,
    "abbr": "PTD10",
    "label": "10-19 yd TD pass bonus"
}, {
    "id": 177,
    "abbr": "PTD20",
    "label": "20-29 yd TD pass bonus"
}, {
    "id": 178,
    "abbr": "PTD30",
    "label": "30-39 yd TD pass bonus"
}, {
    "id": 179,
    "abbr": "RTD0",
    "label": "0-9 yd TD rush bonus"
}, {
    "id": 180,
    "abbr": "RTD10",
    "label": "10-19 yd TD rush bonus"
}, {
    "id": 181,
    "abbr": "RTD20",
    "label": "20-29 yd TD rush bonus"
}, {
    "id": 182,
    "abbr": "RTD30",
    "label": "30-39 yd TD rush bonus"
}, {
    "id": 183,
    "abbr": "RETD0",
    "label": "0-9 yd TD rec bonus"
}, {
    "id": 184,
    "abbr": "RETD10",
    "label": "10-19 yd TD rec bonus"
}, {
    "id": 185,
    "abbr": "RETD20",
    "label": "20-29 yd TD rec bonus"
}, {
    "id": 186,
    "abbr": "RETD30",
    "label": "30-39 yd TD rec bonus"
}, {
    "id": 187,
    "abbr": "DPTSA",
    "label": "D/ST Points Allowed"
}, {
    "id": 188,
    "abbr": "DPA0",
    "label": "D/ST 0 points allowed"
}, {
    "id": 189,
    "abbr": "DPA1",
    "label": "D/ST 1-6 points allowed"
}, {
    "id": 190,
    "abbr": "DPA7",
    "label": "D/ST 7-13 points allowed"
}, {
    "id": 191,
    "abbr": "DPA14",
    "label": "D/ST 14-17 points allowed"
}, {
    "id": 192,
    "abbr": "DPA18",
    "label": "D/ST 18-21 points allowed"
}, {
    "id": 193,
    "abbr": "DPA22",
    "label": "D/ST 22-27 points allowed"
}, {
    "id": 194,
    "abbr": "DPA28",
    "label": "D/ST 28-34 points allowed"
}, {
    "id": 195,
    "abbr": "DPA35",
    "label": "D/ST 35-45 points allowed"
}, {
    "id": 196,
    "abbr": "DPA46",
    "label": "D/ST 46+ points allowed"
}, {
    "id": 197,
    "abbr": "DPAPG",
    "label": "D/ST Points Allowed Per Game"
}, {
    "id": 198,
    "abbr": "FG50",
    "label": "FG Made (50-59 yards)"
}, {
    "id": 199,
    "abbr": "FGA50",
    "label": "FG Attempted (50-59 yards)"
}, {
    "id": 200,
    "abbr": "FGM50",
    "label": "FG Missed (50-59 yards)"
}, {
    "id": 201,
    "abbr": "FG60",
    "label": "FG Made (60+ yards)"
}, {
    "id": 202,
    "abbr": "FGA60",
    "label": "FG Attempted (60+ yards)"
}, {
    "id": 203,
    "abbr": "FGM60",
    "label": "FG Missed (60+ yards)"
}, {
    "id": 204,
    "abbr": "O2PRET",
    "label": "Offensive 2pt Return"
}, {
    "id": 205,
    "abbr": "D2PRET",
    "label": "Defensive 2pt Return"
}, {
    "id": 206,
    "abbr": "2PRET",
    "label": "2pt Return"
}, {
    "id": 207,
    "abbr": "O1PSF",
    "label": "Offensive 1pt Safety"
}, {
    "id": 208,
    "abbr": "D1PSF",
    "label": "Defensive 1pt Safety"
}, {
    "id": 209,
    "abbr": "1PSF",
    "label": "1pt Safety"
}, {
    "id": 210,
    "abbr": "GP",
    "label": "Games Played"
}]
OD1995 commented 3 years ago

@joelataccelm Yeah I did it eventually (manually) but looks like you've got it covered. How did you do it?

joelataccelm commented 3 years ago

Found in the /commons/main.js on https://fantasy.espn.com/football/league/settings?leagueId={leagueId}&view=scoring

cwendt94 commented 3 years ago

Thanks for figuring out the mapping! I will add this in for League Settings before the new season starts!

jdyken commented 1 year ago

You just saved me a ton of headaches Joel. Thank you! Can I buy you a beer? :-)

DesiPilla commented 1 year ago
[{
  "id": 0,
  "abbr": "PA",
  "label": "Each Pass Attempted"
}, {
  "id": 1,
  "abbr": "PC",
  "label": "Each Pass Completed"
}, 
      ...
  "id": 210,
  "abbr": "GP",
  "label": "Games Played"
}]

@cwendt94 can we add this to the wiki or somewhere more visible? This is a lifesaver.

cwendt94 commented 1 year ago

I totally forgot about this issue, thanks for reminding me. I will add this to the football settings in the next couple days!

cwendt94 commented 1 year ago

This is now added in football settings under scoring_format field!