toddrob99 / MLB-StatsAPI

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

Base running data in the boxscore #59

Closed Zkatz72 closed 3 years ago

Zkatz72 commented 3 years ago

I found this wrapper and I've really enjoyed using it so far. However, I was curious as to why there is no base running data (i.e CS and SB) for each game in the game's boxscore. The boxscores look identical to the ones on MLB At Bat, just without the base running data.

toddrob99 commented 3 years ago

Mostly because it wasn't on my mind when I wrote the function that generates the boxscore. The functions that are built into the wrapper are not really meant to satisfy most use cases. They are meant to show examples of how to use the statsapi.get() method to retrieve and work with data from the API. If they are useful for some people, I consider that to be a bonus.

Zkatz72 commented 3 years ago

Oh all right. Thanks! I am curious though: what exactly is the best way to see the stolen bases recorded in a single game?

toddrob99 commented 3 years ago

The statsapi.boxscore_data() method that statsapi.boxscore() uses to retrieve the date from the API actually includes stolen bases, it's just not written to the boxscore. You could make a copy of statsapi.boxscore_data() and add caughtStealing to the fields param (currently line 445), then make a copy of statsapi.boxscore() and add sb/cs to the batter template along with where each batter is written out (away, home. You'll need to account for the extra length in rowLen (not sure after a quick glance if there are other spots).

You could also just take the API call from statsapi.boxscore_data(), add caughtStealing to the field param, and do whatever you want with the data if you want to do something other than print a full boxscore. The data comes from the game endpoint. You'll find a list of batters in the result under result["liveData"]["boxScore"]["teams"]["away"]["players"]["ID592626"]["stats"] (replace away with home for home team, and replace ID592626 with ID<personId> where <personId> is an element in the batters list at result["liveData"]["boxScore"]["teams"]["away"]["batters"] (or home).

Zkatz72 commented 3 years ago

I see. Thanks for your help.