mta-api

Simple flask api. Countdown to next train for each station in the subway system. Uses MTA Realtime Feeds: https://api.mta.info/#/subwayRealTimeFeeds

To run:

  1. Create virtual environment and activate:

python3 -m venv env

source env/bin/activate

  1. Install requirements:

pip install -r requirements.txt

  1. Get api key from https://api.mta.info/#/AccessKey and store the following in a .env file in the root of the directory:

MTA_API_KEY="<api-key>"

export FLASK_ENV=development

export FLASK_APP=index.py

  1. Run Flask app

flask run

  1. To find the next train for the stop, go to subway_metadata/stops.csv to find your stop. For example, 137th St City College Station is code '115'. (Do not enter 115N or 115S)
  2. Navigate to:

http://127.0.0.1:5000/api/stops/115

API fields:

  • direction: N (uptown), S(downtown)
  • nextTime: time in seconds to next train
  • route_id: The route name for the train, see subway_metadata/routes.csv for the routes table.

Notes:

Things to add:

  • Subway alerts and delays
GitHub - kalyani-subbiah/mta-api at pythonawesome.com
Simple api that calculates countdown to train arrival for subway stops. May be expanded to include other features. - GitHub - kalyani-subbiah/mta-api at pythonawesome.com