Skip to content

tadhgj/GodLoc

Repository files navigation

GodLoc

Records TransLoc bus locations and stores them in a json file.

fourth.py

Usage

python3 fourth.py

What does it do?

From 4AM to 2AM, this records Rutgers bus locations every 5 seconds and stores them in a json file.

In more technical terms: Sends a request to the TransLoc API every 5 seconds, stores the data in a json file with the date formatted. Leaves two log files:

  • test.log - so you can run tail -f test.log and see the output
  • EST_%Y-%m-%d_%H:%M:%S_busThird.log - so you can view previous logs

The bus data file is formatted as busData-YYYY-MM-DD.json

(you can customize the locations of these files with outputDir)

web front-end

Usage

cd web

python3 -m ../fetchRoutes.py

python3 -m ../pullLocal.py -date YYYY-MM-DD -ip xxx -user xxx-password xxx

python3 -m http.server

What does it do?

It's a map viewer for the data produced by fourth.py (and now fifth.py)

It visualizes buses using their route colors, places stops on the map, and can draw the last 10 points of any bus's position when clicked. A slider is used to select the time of day to view.

Todo:

  • Flesh out selectBus mechanic
  • Make much more performant (slow on M1 mac is not a good sign)
  • Don't show "dead" buses (in-between running sessions)
  • Overall good UI/UX
  • theorize how to load partial data to speed up loading times
  • develop separate "currently stopped" system with fifth.py

Why?

Transloc has a great website, it's actually very usable, robust, and fast. It's only limitation is that it only displays realtime data.

Because re-inventing the wheel is fun, I decided to make a historical API.

With this data, I hope that I can answer some questions like:

  • How long do Rutgers bus drivers actually spend on their breaks?
  • When can I realistically expect the first and last bus of the day for any given route?

August Update

TransLoc has been replaced with PassioGo for Rutgers's bus system. In the process of migrating.

Notable libraries used

  • ujson (optional, faster than regular python json library) - I needed this to run it at a 5 second interval on a particularly low end VPS
  • pytz (timezone support) - I run my script on a server outside my timezone, so I needed this

fetchRoutes.py

Usage

python3 fetchRoutes.py

What does it do?

Fetches routes, stops, and segments from the TransLoc API and stores them in 3 json files.

Why?

Some data does not change, like route names and segments. Also, I just wanted to never have to deal with Google's polyline encoding again.

Notable libraires used

  • polyline (for decoding polyline segments - hint, they're encoded with Google's polyline algorithm. That's what that gibberish is.)

Footnotes

Requirements

  • Your own API key from TransLoc (free)
  • Python 3.something I believe

License

It's my code. Have fun & make something cool. Credit me.

(legally) GNU General Public License v3.0 See LICENSE for more information.

Author

Tadhg Jarzebowski

Acknowledgements

  • TransLoc for providing a free API with (basically) no rate limits
  • ChatGPT actually told me it was Google's polyline decoding