Skip to content

Python scripts and Flask app that transform, store, and expose HRT Bus data through a RESTful API

Notifications You must be signed in to change notification settings

zirman/hrt-bus-api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hrt-bus-api

Python scripts and 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

bus.codeforhamptonroads.org

Problem

HRT exposes the real time location of there 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 schedulded stop times for a single day in MongoDB.

Expose Data - Python Flask

Setup for Local Development

  1. Install Python 2

  2. Install virtualenv

  3. Clone this repo

  4. Create a virtual environment in the top level directory of the repo

    $ virtualenv venv --distribute
    
  5. Activate the environment

    $ source venv/bin/activate
    
  6. Install 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

  1. Set MongoDB URI (substitue your own MongoDB instance if you have one)

    $ export MONGO_URI=mongodb://hrt_web_app:[email protected]:45897/hrt
    
  2. Change to the web directory and run the flask app

    $ cd web
    $ python app.py 
    
  3. Browse 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

About

Python scripts and Flask app that transform, store, and expose HRT Bus data through a RESTful API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 85.5%
  • Python 14.5%