/bus_bot

Primary LanguagePython

Bus bot

Telegram bot to notify when seats are available on a bus.

Requests

List of requests for the information we need

API Description Used by URL Query Parameters? Notes
eligible_journeys Get journeys for pass ID Rides page https://app.zeelo.co/api/travels/38u1fj13-rfd8-q99a-ap22-ao92929ifikf/elegible-journey-groups
stops Get stops Rides page https://app.zeelo.co/api/stops/by_id?page=1&per_page=25
journeys Get journeys Pass page https://app.zeelo.co/api/travel-passes/38u1fj13-rfd8-q99a-ap22-ao92929ifikf/eligible-journey-groups
capacity Get capacity Pass page https://app.zeelo.co/api/journeys/capacity_between_stops

Journeys URL parameters

Parameter Description Example
product_id Product ID 38u1fj13-rfd8-q99a-ap22-ao92929ifikf
origin_stop_id[] Origin stop ID 38u1fj13-rfd8-q99a-ap22-ao92929ifikf
destination_stop_id[] Destination stop ID 38u1fj13-rfd8-q99a-ap22-ao92929ifikf
tier_id[] Tier ID 38u1fj13-rfd8-q99a-ap22-ao92929ifikf

Example URL

https://app.zeelo.co/api/travel-passes/38u1fj13-rfd8-q99a-ap22-ao92929ifikf/eligible-journey-groups?product_id=38u1fj13-rfd8-q99a-ap22-ao92929ifikf&origin_stop_id[]=38u1fj13-rfd8-q99a-ap22-ao92929ifikf&destination_stop_id[]=38u1fj13-rfd8-q99a-ap22-ao92929ifikf&tier_id[]=38u1fj13-rfd8-q99a-ap22-ao92929ifikf

Requirements

Requirement Version
Python 3.11.1

Commands

Set up environment

python -m venv env

Install dependencies

pip install -r requirements.txt

Run

python ./bot.py

Telegram credentials

To obtain an access token for telegram, see help page, but in essence, talk to the BotFather.

The access token is used via an environment variable, or a .env file, which is not tracked by git.

Also in the environment should be an "admin ID", where errors are sent via the error handler.

touch .env
TELEGRAM_BOT_ACCESS_TOKEN=...
ADMIN_USER_ID=...

Persistent data

To store each user's preferred stops and reminder preference, a persistent pickle file is used. This is not tracked by git. This uses the Persistence API from python-telegram-bot.

persistent_data = PicklePersistence(filepath="bot_data.pickle")
application = Application.builder().token(API_KEY).persistence(persistent_data).build()

Deploy on remote server

Set up environment on server

ssh root@...
cd ~/python
git clone https://github.com/alifeee/bus_bot.git
cd bus_bot
sudo apt-get update
sudo apt install python3.10-venv
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt
echo {} >> historical_capacities.json

Move over secrets

scp google_credentials.json root@...:~/python/bus_bot/
scp .env root@...:~/python/bus_bot/

Run bot

ssh root@...
cd ~/python/bus_bot
cp bus_bot.service /etc/systemd/system/bus_bot.service
sudo systemctl enable bus_bot.service
sudo systemctl start bus_bot.service
sudo systemctl status bus_bot.service

Update

ssh root@...
cd ~/python/bus_bot
git pull

Then repeat steps in Run