Nbascore Slack Application

Hello everyone,

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:

https://www.fullstackpython.com/blog/build-first-slack-bot-python.html

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

http://data.nba.net/10s/prod/v1/today.json

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:

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!

Cheers!

Lead Traffic Modeler @Ulteig

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store