Skip to content

f3d3/NYCMTA-telegram-bot

Repository files navigation

NYC Subway Train Tracker Bot

GitHub latest commit GitHub latest release GitHub downloads GitHub license made-with-python Google Drive

A Telegram bot to get you real-time information about subway arrivals, departures, and alerts in the New York City subway system.

Features

  • Real-time train status and alerts
  • Information about station stops for each subway line
  • Provision of service and transfer information
  • Possibility of adding favourite station and train direction for quick tracking

Installation

  • Clone this git repository.
git clone https://github.com/f3d3/NYCMTA-telegram-bot
  • Change Directory
cd NYCMTA-telegram-bot
  • Install requirements with pip3
pip3 install -r requirements.txt

Configuration

  1. Add values in config.py.

    Configuration Values

    • BOT_TOKEN - Get it by contacting to BotFather
    • MTA_API_key - Get it by creating an MTA developer account
    • LIST_OF_ADMINS - List of Telegram User ID of users that can access restricted commands.
  2. Create client_secrets.json file.

  3. Add values in settings.yaml.

    Configuration Values

    • client_id - Copy it from client_secrets.json file
    • client_secret - Copy it from client_secrets.json file

Deploy

Run the bot with systemd

Create a service file, e.g. /etc/systemd/system/bot.service

[Unit]
Description=Telegram Bot Service
Requires=network.target
After=network.target
StartLimitIntervalSec=0

[Service]
ExecStart=/bin/bash -c 'cd /path-to-folder/NYCMTA-telegram-bot/ && /usr/bin/python3 /path-to-folder/NYCMTA-telegram-bot/bot.py'
Type=simple
User=<user>
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Reload the systemctl daemon. Then, enable the service so that it boots on reboot and start it

sudo systemctl daemon-reload
sudo systemctl enable bot.service
sudo systemctl start bot.service

Run the bot in the background

Use the command below to run the script by getting it to ignore the hangup signal and keep running. Output will be put in nohup.out.

nohup python3 bot.py &

If you do not want an ever-growing nohup.out file, you need to redirect the script's output as

nohup python3 bot.py > /dev/null 2>&1 &

Copyright & License