Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alifeee/bus_bot
https://github.com/alifeee/bus_bot
Last synced: 23 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/alifeee/bus_bot
- Owner: alifeee
- Created: 2023-07-01T11:00:55.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-11T23:05:30.000Z (4 months ago)
- Last Synced: 2024-07-12T01:23:26.988Z (4 months ago)
- Language: Python
- Size: 81.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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] | |❌||
| stops | Get stops | [Rides page] | |❌||
| journeys | Get journeys | [Pass page] | |✅||
| capacity | Get capacity | [Pass page] | |❌||[Rides page]: https://app.zeelo.co/rides/jlr
[Pass page]: https://app.zeelo.co/my-zeelo/travel-pass/38u1fj13-rfd8-q99a-ap22-ao92929ifikf## 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
## Requirements
| Requirement | Version |
| ----------- | ------- |
| Python | 3.11.1 |## Commands
### Set up environment
```bash
python -m venv env
```### Install dependencies
```bash
pip install -r requirements.txt
```### Run
```bash
python ./bot.py
```## Telegram credentials
To obtain an access token for telegram, see [help page](https://github.com/python-telegram-bot/python-telegram-bot/wiki/Introduction-to-the-API), but in essence, talk to the [BotFather](https://t.me/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.
```bash
touch .env
``````.env
TELEGRAM_BOT_ACCESS_TOKEN=...
ADMIN_USER_IDS=...
```## 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](https://github.com/python-telegram-bot/python-telegram-bot/wiki/Making-your-bot-persistent) from [python-telegram-bot][ptb].
[ptb]: https://github.com/python-telegram-bot/python-telegram-bot/
```python
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
```bash
ssh server
mkdir -p /usr/alifeee
cd /usr/alifeee
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
# create user
sudo adduser --system --no-create-home --group bus_bot
sudo chown -R alifeee:bus_bot .
chmod g=rw historical_capacities.json
chmod g=rw bot_data.pickle
```### Move over secrets
```bash
scp google_credentials.json server:/env/alifeee/bus_bot/
scp .env server:/usr/alifeee/bus_bot/
```### Run bot
```bash
ssh server
cd /usr/alifeee/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
```bash
ssh server
cd /usr/alifeee/bus_bot
git pull
```Then repeat steps in [Run](#run-bot)