hrt-bus-api
HRT Bus API publishes real time bus data from Hampton Roads Transit through an application programming interface for developers to make apps from it.
HRT Bus API consists of Python scripts and a Flask app that transform, store, and expose HRT Bus data through a RESTful API. API's don't make for good demos, so we've created an HRT Bus Finder App.
Try It
- Web App: hrtb.us
- REST Api: api.hrtb.us/api
Problem
HRT exposes the real time location of their buses at ftp://216.54.15.3/Anrd/hrtrtf.txt. Unfortunately, this file gives us less than five minutes of data and most of the entries don't have a route number associated with them. Riders lookup bus information by route number, so without it, the data isn't very useful.
Solution
Transform and Store Data - Python Scripts
- Process FTP - Fetches the HRT FTP file and stores the data in MongoDB. Also attempts to set route number when it's missing.
- Process GTFS - Fetches the HRT GTFS package and stores the scheduled stop times for a single day in MongoDB.
Expose Data - Python Flask
Web App
- RESTful API
Bus Finder
Setup for Local Development
- Install Python 2
- Install virtualenv
- Clone this repo
Create a virtual environment in the top level directory of the repo
$ virtualenv venv --distributeActivate the environment
$ source venv/bin/activate-OR- for Windows
$ venv\Scripts\activate.batInstall dependencies
$ pip install -r requirements.txt
Scripts
If you would like to develop the scripts, you will need your own MongoDB instance. I recommend MongoLab. If you just want to work on the web app, feel free to skip the part about the scripts. Read-only access is provided to a MongoDB instance that is being populated with real-time bus data.
Web App
Set MongoDB URI (substitue your own MongoDB instance if you have one)
$ export MONGO_URI=mongodb://hrt_web_app:cfa@ds045897.mongolab.com:45897/hrt-OR- for Windows
$ set MONGO_URI=mongodb://hrt_web_app:cfa@ds045897.mongolab.com:45897/hrtChange to the web directory and run the flask app
$ cd web $ python app.pyBrowse to
http://0.0.0.0:5000/
Deployment
Scripts
- Iron.io - Each script has it's own README with instructions for deployment
Flask Web Application
We're Here to Help
- Ben Schoenfeld - ben.schoenfeld@gmail.com - @oilytheotter
- Search or post to our Google Group for the local "Brigade"
