JRomainG / TGVMaxBot

Telegram bot to automatically notify users when Max Jeune (formerly TGV Max) tickets are available

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TGVMaxBot

A Telegram bot to automatically notify users when Max Jeune (formerly TGV Max) tickets are available for specific dates and train stations.

Installation

TGVMaxBot requires Python 3.7 or newer.

Dependencies can be installed using pip:

$ pip3 install -r requirements.txt

Configuration

You need to create two files: auth.ini and config.ini:

$ cp auth.ini.example auth.ini
$ cp config.ini.example config.ini

Telegram

To send messages using Telegram, you first need to create a Telegram bot. For this, you need to talk to BotFather and issue the /newbot command. Once you are done, BotFather will provide you with a token, save it in the auth.ini file.

Once this is done, you can invite your bot to a Telegram group or channel and retrieve its chat id. After inviting the bot, you can find the chat ID from the https://api.telegram.org/bot{token}/getUpdates URL (replacing {token} with your bot's token).

TGVMaxBot

Finally, you can configure this script by editing the config.ini file. Here are the available options:

Key Type Description
check_interval int How often to check if new tickets are available (in seconds, default: 3600)
allowed_chat_ids list A space separated list of chat IDs in which the bot will answer all users
allowed_user_ids list A space separated list of user IDs to which the bot will always answer
silent_notifications bool Whether to send messages silently (notifications will have no sound)

Running

Simply start the script and let it run in the background:

$ python3 main.py

Docker

You can run the bot directly using Docker:

$ docker build . -t tgvmaxbot
$ docker run -d tgvmaxbot

Systemd service

If you use systemd, you can run the bot as a service. Here is an example configuration file:

[Unit]
Description=TGVMaxBot
After=network.target

[Service]
User=bot
Nice=1
KillMode=mixed
SuccessExitStatus=0 1
ProtectHome=true
ProtectSystem=full
PrivateDevices=true
NoNewPrivileges=true
WorkingDirectory=/var/bots/
ExecStart=/usr/bin/python3 /var/bots/TGVMaxBot/main.py
#ExecStop=

[Install]
WantedBy=multi-user.target

You can save it as /etc/systemd/system/TGVMaxBot.service, and then start it:

$ systemctl daemon-reload
$ systemctl enable TGVMaxBot
$ systemctl start TGVMaxBot

Usage

Simply add your bot to a group channel or start sending it messages. Make sure to authorize your user ID and/or chat ID in config.ini (the /userid and /chatid commands may be useful).

TODO

  • Implement persistence: the bot will forget about all trips after being killed
  • Add date and time picker keyboards
  • Add links to easily book discovered tickets
  • Allow automatically booking discovered trips

About

Telegram bot to automatically notify users when Max Jeune (formerly TGV Max) tickets are available

License:GNU General Public License v3.0


Languages

Language:Python 99.5%Language:Dockerfile 0.5%