This project implements an asynchronous Telegram bot for searching movies.
Initial request (keywords) is made in google
with additional word imdb.
Then the most frequent movie_id
is selected from response using Soup.
The next step is collecting data associated with movie. For this goal is applied IMDB API.
Finally, request and movie title are saved in database. All requests and replies for messages support concurrency.
The bot supports the history of requests by using SQLite.
It is strongly recommended to use Python 3.10 and above versions.
The script requires libraries aiogram
and aiohttp
for concurrent execution.
Necessary packages and versions can be installed with the following command
pip install -r requirements.txt
After cloning the repository and installing requirements two tokens are needed.
- Token for Telegram bot. It can be taken from BotFather.
- Token for IMDb API. It will be available after registration here.
Then tokens are placed into environment variables
export BOT_TOKEN=<your bot token>
export IMDB_TOKEN=<your imdb token>
python3 bot.py
# or simpler
BOT_TOKEN=<your bot token> IMDB_TOKEN=<your imdb token> python3 bot.py
Possible sequence of messages (U: user, B bot)
U: /start
B: [welcome message]
U: some keywords
B: [title, poster, duration, description, links, etc.]
U: /history
B: [history of requests]
U: /stats
B: [statistics of requests]
U: /delete request
B: Deleted 2 items. # request has been deleted from the database
U: /link title year
B: [link to movie description on IMDb]
U: /info movie_id (or link) # generating description without searching by keywords
B: [the same with 4th line]
Note: History depends on user id (independent for everyone). It is saved on HDD and
can be deleted only by /delete
and /clear
commands.
During the next several months bot is available here.