Hockey Twitter Bot – Open Sourced

Posted on

Today, I finally uploaded the code that runs @NJDevilsGameBot to my Github account.

A few years back, when I got my first Raspberry Pi and learned that the NHL had an API (although no official documentation exists, the current community driven documentation can be found here), I decided to pick up the basics of Python and build something. I ended up putting together a python script that would use the NHL API schedule endpoint to watch for changes in score of New Jersey Devils games and then trigger red beacon lights and the goal song through my receiver. The code was messy and the setup was too unique so I never published it anywhere.

A few weeks ago I decided I want to take some of the foundations built in the aforementioned code, advance my Python skills a bit and Hockey Twitter Bot was born. At its core, the bot is a python script that parses the NHL Schedule & Live Feed API endpoints to gather relevant game events and tweet them to the game bot Twitter account. Some more information (such as events that are parsed and tweeted) and other technical details can be found in the README of the Github repository.

The code is very much a work in progress and considering my Python skills are far mediocre at best, the code will always be. To be honest, the only reason I put the code onto Github is because I am hoping that people that are more proficient in Python than me find it and send me pull requests to fix bugs, remove redundant code or just tell me what I am doing wrong and how it can be better.

I have embedded some sample tweets at the bottom of the post as well just to showcase some sample functionality.

PS – if you are a Devils fan & are not following @NJDevilsGameBot – why not?

Pre-game tweet sent out one game days

Final score & boxscore stats image

3-Stars of the Game

A goal scored with assists added via quote tweet
Scoring changes are done the same way

End of period (showing shot totals)

Starting Lineups (as accurate as possible)