r/mlbdata•
Monktoken

Trying to read play by play information, only works some of the time.

Long story short I'm trying to do a project that lights up some LEDs every time there's a hit or a scoring play. I'm at the point using toddrob99's python wrapper that I can get when some type of play or putout occurs which is awesome... but it's not consistent.

I've tried upping the refresh rate to every 5 seconds but eventually I hit the API too much and I get timed out. For some reason when I refresh every 10 seconds it misses out on some hits that occur. I'm not sure if it has to do with how Spring Training gets data entered or what.

Has anyone tried to do a play by play program before? Any tips you can offer?

Posted Mar 17, 2025, 4:15 AM UTC

29
SidneyBlahaj•

Using the websocket might be better here. It’s a bit hard to find up-to-date info on it, but this post helped me get started: https://www.reddit.com/r/mlbdata/s/26vruFtUjI

I think some of the info in there like the “Gameday5” thing might be a bit outdated, but it was enough info for me to establish a connection and print all the events in real time the other day.

The info you get is a bit barebones and might require some api calls to make full sense of/get additional context, but it does send a message for every score change I believe

1
MonktokenOP•

Every little bit helps, I appreciate it!

1
SidneyBlahaj•

No problem, I’m actually working on a similar project so feel free to shoot me any questions and I’ll share what little insight I might have. Good luck!

1
IliannnnnnMod•

What is outdated about the "Gameday5"? Did they change it?

1
SidneyBlahaj•

As far as I can tell it’s not needed anymore. The server doesn’t send it and neither do you need to to connect

2
IliannnnnnMod•

That makes sense. Thanks for telling me.

1
AlecM33•

I would recommend using the web socket. MLB's Gameday site uses a combination of the websocket connection and HTTP calls to keep up with the live game state. I had some trouble figuring it out and chronicled it in this post here.

The resulting code I wrote to report games is open source as a part of this project. Key logic is in modules/gameday.js and modules/diff-patch.js

1
MonktokenOP•

Websockets are brand new to me, but from the posts linked around in your comment it does seem that's exactly what I'm looking for. I have a lot of reading to do, but that's half the fun 😂

Thank you very much!

1
AlecM33•

No problem. I'd recommend using the browser dev tools to spectate the network traffic during a game on Gameday. You can view websocket traffic there, and you will observe it receiving all the events.

1
MonktokenOP•

What do you mean by browser dev tools in this context?

1
AlecM33•

Pressing F12 should bring them up. It shows the console plus a bunch of other tabs, one of which is Network. That will log all the network requests the page is making

1