We realized that there is no application that reports NBA results of the day on Slack during one of our meaningless conversations about sports. Since it was the long weekend, I started to look for potential resources I can utilize to bring the scores to our slack channel.
Reading Matt Makai’s post about how to build a slack bot with python, I was able to initialize the first version of the bot following the steps explained here:
The next step was to find a way to reliable get live scores. First, I gave nba_api (super cool) a try.
However, it looks like scoreboard and scoreboardv2 endpoints are not actually reporting real-time scores, instead, they are updated at intervals. Therefore, it is kind of pointless to use these endpoints. I quickly realized what I need is much more simple so I decided to code it myself. Quick internet search and reading some posts on Reddit lead me to this
It lists all the available API endpoints that anyone can send requests to. No key is needed which is perfect for my simple bot. Swar’s python library (nba_api) uses stats.nba.com that is a little different than data.nba.net
Data.nba.net reports real-time scores as well as historical ones. Scores are updated real time and it is even faster than what you see on Google when you search for NBA scores.
I created the bot with 3 main functionalities. These functionalities are emerged from our need to know the score of the game and player stats after the game. All of these functionalities are explained on the Github page. Here is the link for interested developers:
Slack application for live NBA scores. Contribute to ak4728/slack-nbascore-app development by creating an account on…
The first two functionalities are to get the scores and games of the day. You can either use (@ nbascore nba) to get all the games or (@ nbascore team Nets) to get individual games.
This function can generate a score response for a specific team or for all teams. It requires three inputs; response, deltahours and teamid. If the team ID is missing, then it will return all the scheduled games. Otherwise, it will return the games for the given team id. Team names will be converted into team IDs to be read for this function.
The last functionality which we thought we need is to get the statistics of the player from the last game. I am thinking of adding career stats here as well. This function requires player ID and fullname (kind of redundant, I know) of the player. Given the ID, it sends a request and reads the JSON response for the player’s stats for the last game he played in.
It is pretty simple and messy at this point but it works. Thanks for reading!