toddrob99 / MLB-StatsAPI

Python wrapper for MLB Stats API
GNU General Public License v3.0
513 stars 98 forks source link

Is there a way to get a game log for a given player? #111

Closed essentiapip closed 1 year ago

essentiapip commented 1 year ago

Hi,

I have been enjoying the wrapper and have been making extensive use of it in my current project.

My question was; if I have the player ID of a batter/pitcher and I want to get his game-by-game performance over a given date range, can I do that with your wrapper? Is there a function for it? Do you know how I can do this alternatively?

My end goal is that for a given pitcher or batter id, i get back the game records of the respective players and the appropriate statistics (e.g. atBats).

My current way of getting this is very recursive and slow and makes it very difficult to track the flow of the code to extract meaningful features.

Really looking forward to hearing back on this,

Thanks!

toddrob99 commented 1 year ago

I think the person_stats endpoint gets you close. You need the gamePks, which you can get from the player's team's schedule, and then you would loop over the person_stats endpoint for each gamePk. Here is an example of the response for the person_stats endpoint: http://statsapi.mlb.com/api/v1/people/605151/stats/game/531368. You could use statsapi.get() to query the API.