Sports Games
Tools Used
I built this project using Python. I used the Requests library to make API requests.
The API that I used is called SportScore. It's hosted on Rapid API, an API hub that has thousands of free API's
To send the text messages through Whatsapp, I used Twilio's Whatsapp API.
Initial Setup
There is a JSON file, called teams.json
, that contains
all the teams that I chose. Each team has a team ID, a league ID, and
a sport ID.
There must be an API key that can be obtained from RapidAPI after signing up.
There must also be an account SID and an authentication token to use Twilio's Whatsapp API. To use Twilio's API, you have to pay an initial $20.
Main Application
The program runs everyday at 12:01 AM. For every team there is in the
teams.json
file, an API call is made. The response contains
the game's date, time, opponent, and many more details. The response is
then scraped to check if there are games on the day the program runs.
After all responses have been scraped, a single string is sent through Twilio's Whatsapp API to myself.
Issues Faced
One of the issues that I faced was that the API response gave me the time in UTC +0. I live in Saudi Arabia which is UTC +3. So games that are between 9 PM and 12 AM UTC +0 do not appear on the same day's API response, but do on the previous day's API response.
To fix this issue, I made the application check if the game is happening today or the day after by adding 3 to the time of the game. If that number is more than, or equal, to 24, that means that the game is happening the day after (after 12 AM) and not today.
So I made another JSON file called tomorrow.json
that contains the games
that are going to be played on the next day.
This changes the workflow of the application. Now it has to check tomorrow.json
before making API calls. If tomorrow.json
is empty, then proceed to making API
calls. Else, add the content of tomorrow.json
to today's games, make the API calls,
then send the message.
If there are no games on a certain day, the messages simply displays "No games today"
Environment
The program runs on my tablet that runs Ubuntu Linux. It uses a program called Crontab. Crontab is like Windows' Task Scheduler. It allows you to run programs at specific times or at intervals.
Here's the link to the Github repo