The app consists of API service, which provides information about football clubs, and telegram bot.
API service
-
API service has endpoints:
- GET /clubs (information about clubs)
- GET /clubs/{club_id} (information about each club)
- POST /clubs (creates a club)
- endpoints to export information into the telegram bot.
-
The data about club are stored in PostgreSQL, the data about pages' views are stored in MongoDB (inc. time, user IP).
-
There are cron jobs, implemented with using Celery, which export data about pages' views to .csv file and to plots in .png format.
-
The are three types of plots:
- with bars, which shows total views of clubs during the specific period of time,
- lineplot, which shows dynamics of views during the specific period of time,
- displot, which shows distribution of data.
-
All the files are saved to Google Disk.
Telegram bot
- In the bot with /start you will have several buttons:
- buttons for getting plots,
- buttons for getting information, using a source Api-Football.
- First you'll receive the id of Celery task, which is responsible for plot building.
- You can check the status of the task by sending task ID to the bot. The bot will return you on of several possibilities (PENDING, STARTED, SUCCESS).
- If the task status is SUCCESS, you can receive the plot from bot by sending the command /result.
- The bot asks for the data from API service. Information about tasks' statuses is stored in Redis database (which is used as backend in Celery app).
This project was built using these tools:
Tool | Description |
---|---|
FastAPI | "Web framework for building APIs with Python" |
Python Telegram Bot | "This library provides a pure Python, asynchronous interface for the Telegram Bot API" |
Celery | "A task queue with focus on real-time processing, while also supporting task scheduling" |
PostgreSQL | "An open source object-relational database system" |
SQLAlchemy | "The Python SQL toolkit and Object Relational Mapper" |
MongoDB | "A NoSQL database program" |
Redis | "The open source, in-memory data store" |
seaborn | "A Python data visualization library based on matplotlib" |
poetry | "Python dependency management and packaging made easy" |
Copy a project
$ git clone [email protected]:Dddarknight/analytics-publisher.git
$ cd analytics-publisher
Set up environment variables
$ touch .env
# You have to fill .env file. See .env.example.
# You will have to:
# 1) fill username and password fields for PostgreSQL, RabbitMQ. If you don't have these credentials, please follow the instructions in the official documentation.
# 2) make a telegram bot and put its token to a TG_API_TOKEN variable.
# 3) register on Api-Football and put api-token to a API_FOOTBALL variable.
Set up the environment
$ pip install poetry
$ make install
Launch API server
$ make run
Launch a bot
$ make bot_
Launch Celery
# Launch Celery scheduled tasks
$ celery -A api_app.celery_tasks beat --loglevel=info
# Launch the Celery worker (it's also necessary for the bot)
$ celery -A api_app.celery_tasks worker --loglevel=info --pool solo