8000 GitHub - Thevesh/traffic-monitor: Python code to monitor a route at your desired frequency, using the Google Directions API
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Thevesh/traffic-monitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This code should help you quickly deploy your own version of a traffic monitor, with output as shown here.

Setup requirements:

  1. Rename constants.example to constants.py, which has been added to the gitignore to prevent accidental leakage of secrets (best practice is to use an environment variable, but this will do).

  2. python3 -m venv .venv and then pip3 install -r requirements.txt

  3. Do the following to complete constants.py:

  • Create a Google Cloud Platform (GCP) account, enable the Directions API, and add your API key in.
  • Create a Telegram bot (visit @BotFather on Telegram) and add the bot's key.
  • Create a Telegram channel, add the bot as an admin, and add the channel's ID (use @myidbot to get the ID).
  1. Change the chains and locations in dep/stops.csv to monitor your own routes.

Deployment:

Not going to be too prescriptive, as most will have their own preference, but the live use case was deployed from a small VM running Ubuntu 22.04 LTS, using crontab. Nothing fancy.

This was the .sh script in ~/crons/traffic.sh (don't forget to chmod + x ~/crons/traffic.sh):

#!/bin/bash
# activate Python venv and run daily script
source ~/YOUR_GIT_FOLDER_PATH/.venv/bin/activate
cd ~/YOUR_GIT_FOLDER_PATH/
python3 cron_traffic_raya.py

And this was the crontab file (amend as desired to reduce/increase frequency, which will correlate to costs):

0-59/20 * * * * ~/crons/traffic.sh

About

Python code to monitor a route at your desired frequency, using the Google Directions API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0