yahoo_fantasy_api icon indicating copy to clipboard operation
yahoo_fantasy_api copied to clipboard

Cannot parse player stats with req_type = 'date' for specific days

Open PChabelski opened this issue 4 years ago • 3 comments

I'm running into an issue when trying to parse player stats using the date req_type. The code snippet in question is as follows:

from yahoo_oauth import OAuth2
import yahoo_fantasy_api as yfa
import json

oauth = OAuth2(None, None, from_file='oauth2.json')
gm = yfa.Game(oauth, 'nhl')
ids = gm.league_ids(year=2020)
lg = gm.to_league(ids[0])
day = datetime.date(2021,1,16) # can select any random day the player has played
player=[3983] # can select any player
lg.player_stats(player[0],req_type='date',date=day)

And here is my output:

[2021-08-29 21:43:43,300 DEBUG] [yahoo_oauth.oauth.init] Checking [2021-08-29 21:43:43,301 DEBUG] [yahoo_oauth.oauth.token_is_valid] ELAPSED TIME : 1052.1923336982727 [2021-08-29 21:43:43,303 DEBUG] [yahoo_oauth.oauth.token_is_valid] TOKEN IS STILL VALID [{'player_id': 3983, 'name': 'Phil Kessel', 'position_type': 'P', 'GP': '-', 'G': '-', 'A': '-', 'PTS': '-', '+/-': '-', 'PIM': '-', 'PPG': '-', 'PPA': '-', 'PPP': '-', 'SHP': '-', 'GWG': '-', 'SOG': '-', 'S%': '-', 'HIT': '-', 'BLK': '-'}]

For the date selected, we should see something for these categories. I can pull season info for players with no issues. I wonder if it's an issue with the datetime format? Any insight would be greatly appreciated.

PChabelski avatar Aug 30 '21 01:08 PChabelski

I'm curious if you resolved your issue. I am having a similar problem - except for me no stats are returning at all. I'm worried I may need to scrape the data I need using selenium...

duncanjamesbell avatar Jun 20 '22 20:06 duncanjamesbell

This looks like a restriction with the Yahoo! API. I'm only able to pull game stats for the current year. And I can only pull from mlb. I don't get any nhl stats. Here is an example of pulling stats for Tim Anderson of the White Sox's. Notice, last year stats are empty but stats from this year are okay.

from yahoo_oauth import OAuth2
import yahoo_fantasy_api as yfa
import json
import datetime

oauth = OAuth2(None, None, from_file='oauth2.json')
gm = yfa.Game(oauth, 'mlb')
ids = gm.league_ids(year=2021)
lg = gm.to_league(ids[0])
day = datetime.date(2021,4,1)
player=[9897] # Tim Anderson
lg.player_stats(player[0],req_type='date',date=day)
[{'player_id': 9897,
  'name': 'Tim Anderson',
  'position_type': 'B',
  'G': '-',
  'GS': 0.0,
  'AB': '-',
  'R': '-',
  'H': '-',
  '1B': '-',
  '2B': '-',
  '3B': '-',
  'HR': '-',
  'RBI': '-',
  'SH': '-',
  'SF': '-',
  'SB': '-',
  'CS': '-',
  'BB': '-',
  'IBB': '-',
  'HBP': '-',
  'SO': '-',
  'GDP': '-',
  'TB': '-',
  'PO': '-',
  'A': '-',
  'E': '-',
  'FLD%': '-',
  'AVG': '-',
  'OBP': '-',
  'SLG': '-',
  'OPS': '-',
  'PA': '-',
  'DP': '-'}]

day = datetime.date(2022,4,10)
lg.player_stats(player[0],req_type='date',date=day)
[{'player_id': 9897,
  'name': 'Tim Anderson',
  'position_type': 'B',
  'G': 1.0,
  'GS': 1.0,
  'AB': 5.0,
  'R': 2.0,
  'H': 3.0,
  '1B': 1.0,
  '2B': 2.0,
  '3B': 0.0,
  'HR': 0.0,
  'RBI': 0.0,
  'SH': 0.0,
  'SF': 0.0,
  'SB': 0.0,
  'CS': 0.0,
  'BB': 0.0,
  'IBB': 0.0,
  'HBP': 0.0,
  'SO': 1.0,
  'GDP': 0.0,
  'TB': 5.0,
  'PO': 1.0,
  'A': 0.0,
  'E': 0.0,
  'FLD%': 1.0,
  'AVG': 0.6,
  'OBP': 0.6,
  'SLG': 1.0,
  'OPS': 1.6,
  'NSB': 0.0,
  'PA': 5.0,
  'DP': 0.0}]

spilchen avatar Jul 19 '22 22:07 spilchen

@spilchen I know it's not super helpful in regards to where the error might be, but I was able to confirm with my (admittedly competing) Yahoo API wrapper library that retrieving stats for Tim Anderson for the above dates ("2021-04-01" and "2022-04-10") works with Yahoo's API without issue:

For 2021:

{
  "display_position": "SS",
  "editorial_player_key": "mlb.p.9897",
  "editorial_team_abbr": "CWS",
  "editorial_team_full_name": "Chicago White Sox",
  "editorial_team_key": "mlb.t.4",
  "eligible_positions": [
    "SS",
    "Util"
  ],
  "has_player_notes": 1,
  "headshot": {
    "size": "small",
    "url": "https://s.yimg.com/iu/api/res/1.2/yrz7bGZfGG3vNZ6yPTljpg--~C/YXBwaWQ9eXNwb3J0cztjaD0yMzM2O2NyPTE7Y3c9MTc5MDtkeD04NTc7ZHk9MDtmaT11bGNyb3A7aD02MDtxPTEwMDt3PTQ2/https://s.yimg.com/xe/i/us/sp/v/mlb_cutout/players_l/05052022/9897.png"
  },
  "is_undroppable": 0,
  "name": {
    "ascii_first": "Tim",
    "ascii_last": "Anderson",
    "first": "Tim",
    "full": "Tim Anderson",
    "last": "Anderson"
  },
  "player_id": 9897,
  "player_key": "404.p.9897",
  "player_notes_last_timestamp": 1657953889,
  "player_stats": {
    "coverage_type": "date",
    "stats": [
      {
        "stat": {
          "stat_id": 60,
          "value": 0.0
        }
      },
      {
        "stat": {
          "stat_id": 7,
          "value": 1.0
        }
      },
      {
        "stat": {
          "stat_id": 12,
          "value": 0.0
        }
      },
      {
        "stat": {
          "stat_id": 13,
          "value": 0.0
        }
      },
      {
        "stat": {
          "stat_id": 16,
          "value": 0.0
        }
      },
      {
        "stat": {
          "stat_id": 3,
          "value": 0.25
        }
      }
    ]
  },
  "position_type": "B",
  "primary_position": "SS",
  "uniform_number": 7
}

And for 2022:

{
  "display_position": "SS",
  "editorial_player_key": "mlb.p.9897",
  "editorial_team_abbr": "CWS",
  "editorial_team_full_name": "Chicago White Sox",
  "editorial_team_key": "mlb.t.4",
  "eligible_positions": [
    "SS",
    "Util"
  ],
  "has_player_notes": 1,
  "headshot": {
    "size": "small",
    "url": "https://s.yimg.com/iu/api/res/1.2/yrz7bGZfGG3vNZ6yPTljpg--~C/YXBwaWQ9eXNwb3J0cztjaD0yMzM2O2NyPTE7Y3c9MTc5MDtkeD04NTc7ZHk9MDtmaT11bGNyb3A7aD02MDtxPTEwMDt3PTQ2/https://s.yimg.com/xe/i/us/sp/v/mlb_cutout/players_l/05052022/9897.png"
  },
  "is_undroppable": 0,
  "name": {
    "ascii_first": "Tim",
    "ascii_last": "Anderson",
    "first": "Tim",
    "full": "Tim Anderson",
    "last": "Anderson"
  },
  "player_id": 9897,
  "player_key": "412.p.9897",
  "player_notes_last_timestamp": 1657953889,
  "player_stats": {
    "coverage_type": "date",
    "stats": [
      {
        "stat": {
          "stat_id": 60,
          "value": 0.0
        }
      },
      {
        "stat": {
          "stat_id": 7,
          "value": 2.0
        }
      },
      {
        "stat": {
          "stat_id": 12,
          "value": 0.0
        }
      },
      {
        "stat": {
          "stat_id": 13,
          "value": 0.0
        }
      },
      {
        "stat": {
          "stat_id": 16,
          "value": 0.0
        }
      },
      {
        "stat": {
          "stat_id": 3,
          "value": 0.6
        }
      }
    ]
  },
  "position_type": "B",
  "primary_position": "SS",
  "uniform_number": 7
}

Hopefully it's just some small date formatting issue or something, or maybe it could be happening during the mapping of the stat category names to the stats, but I'd try throwing some loggers into the raw data request to check if you're getting the stats back or if something is amiss with the actual request endpoint.

uberfastman avatar Jul 19 '22 23:07 uberfastman