All Projects → neoterix → nyc-mta-arrival-notify

neoterix / nyc-mta-arrival-notify

Licence: MIT license
A basic python script that reads the NYC MTA realtime feed API for subway data and outputs when the next arrival is for a given station.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to nyc-mta-arrival-notify

gtfsrdb
GTFSrDB is a tool to archive gtfs-realtime data to a database.
Stars: ✭ 27 (-40%)
Mutual labels:  gtfs, gtfs-realtime-data, gtfs-realtime
transitime
TheTransitClock real-time transit information system
Stars: ✭ 60 (+33.33%)
Mutual labels:  gtfs, gtfs-realtime
theweekendest
Real-time New York City subway service map
Stars: ✭ 51 (+13.33%)
Mutual labels:  nyc, gtfs
transitland-atlas
an open directory of mobility feeds and operators — powers both Transitland v1 and v2
Stars: ✭ 55 (+22.22%)
Mutual labels:  gtfs, gtfs-realtime
goodservice
Website that detects headway discrepancy on New York City Subway system using live countdown clocks
Stars: ✭ 26 (-42.22%)
Mutual labels:  nyc, gtfs
retro-gtfs
Collect real-time transit data and process it into a retroactive GTFS 'schedule' which can be used for routing/analysis
Stars: ✭ 45 (+0%)
Mutual labels:  gtfs, gtfs-realtime
linked-connections-server
Express based server that exposes Linked Connections.
Stars: ✭ 12 (-73.33%)
Mutual labels:  gtfs, gtfs-realtime
concentrate
Concentrate: combine realtime transit files
Stars: ✭ 23 (-48.89%)
Mutual labels:  gtfs, gtfs-realtime
nyc-infosec
Mapping the NYC Infosec Community
Stars: ✭ 41 (-8.89%)
Mutual labels:  nyc
fastgtfs
A pure Rust library that provides GTFS parsing, navigation, time table creation, and real-time network simulation.
Stars: ✭ 21 (-53.33%)
Mutual labels:  gtfs
currency-api
A demo project on how to test a node/express app with Mocha, Nock and proxyquire (MNP) and code coverage with nyc/istanbul.
Stars: ✭ 19 (-57.78%)
Mutual labels:  nyc
GTFS
Public transport data in GTFS format with schemas, a data package and tests
Stars: ✭ 20 (-55.56%)
Mutual labels:  gtfs
GTFS-Issues
Dokumentation und Verfolgung aktueller Probleme deutschsprachiger GTFS-Datensätze
Stars: ✭ 24 (-46.67%)
Mutual labels:  gtfs
european-transport-operators
NOT UP-TO-DATE ANYMORE, UNMAINTAINED. CHECK european-transport-feeds INSTEAD. List of european long-distance transport operators, available API endpoints, GTFS feeds and client modules.
Stars: ✭ 47 (+4.44%)
Mutual labels:  gtfs
GTFS
.NET implementation of a General Transit Feed Specification (GTFS) feed parser.
Stars: ✭ 55 (+22.22%)
Mutual labels:  gtfs
gtfstools
General Transit Feed Specification (GTFS) Editing and Analysing Tools
Stars: ✭ 31 (-31.11%)
Mutual labels:  gtfs
public-transit-tools
Tools for working with GTFS public transit data in ArcGIS
Stars: ✭ 126 (+180%)
Mutual labels:  gtfs
istanbul-badges-readme
Creates and updates README testing coverage badges with your json-summary
Stars: ✭ 77 (+71.11%)
Mutual labels:  nyc
ts-node-starter
GitHub template to get started with Node.js & TypeScript. ⚡
Stars: ✭ 28 (-37.78%)
Mutual labels:  nyc
nyc-crash-mapper
React Redux web application for viewing, filtering, & comparing trends of automobile collision data published by the NYPD.
Stars: ✭ 15 (-66.67%)
Mutual labels:  nyc

Introduction

This a basic python script that reads the NYC MTA realtime feed API for subway data and outputs when the next arrival is for a given station. It was created as an self-directed educational exercise to build something from scratch and hopefully you might find it useful too!

This script uses the New York MTA real-time data feed for its subway system:

Because the New York MTA real-time data feed uses the GTFS-realtime data exchange format (which is based upon protocol buffers) this script relies on kaporzhu's protobuf3-to-dict package to convert the MTA's GTFS feed into a more python-friendly set of python dictionaries and lists.

Requirements

This script relies on the following packages: Python language bindings for GTFS, protobuf3-to-dict, and dotenv to insert the API key provided by the MTA. If you use PIP, the following commands will do the trick:

pip install --upgrade gtfs-realtime-bindings
pip install protobuf3_to_dict
pip install -U python-dotenv

Access to the MTA live feeds requires signing up for an API key from the NYC MTA: http://datamine.mta.info/user/register

Put API key into the changeme.env file (after API_KEY=) and rename the file into an .env file within the root directory of the Python script.

Script Behavior

In short, the script pulls a realtime feed from the NYC MTA and converts it from GTFS-realtime into Python a set of Python dictionaries and lists (see the samples directory). This feed contains a variety of north and southbound subway trains and their predicted arrival and departure times for whatever stops it has ahead of it, such that each feed contains several times for any one given station and direction. Consequently, the script creates an empty list collected_times to collect these various times. The MTA offers different feeds that correspond to different subway lines, and currently the feed is hardcoded to the B/D subway feed.

The primary function station_time_lookup takes two arguments, a converted MTA data feed and a specific station ID, and loops through various nested dictionaries and lists to (1) filter out active trains, (2) search for the given station ID, and (3) append the arrival time of any instance of the station ID to collected_times. Note that the times in the MTA feed are in epoch time, and require conversion if you wish to display something more human readable (which the script later does).

The specific station ID is currently hardcoded in, and is set for the southbound Broadway-Lafayette stop. The list of subway stops and station IDs may be found in the MTA's collection of static data feeds.

With the collected_times list now populated, you now have a list of all of the predicted arrival times and can do a variety of things with it. The rest of the script sorts this list to find the next two arrival times, pulls the current time to figure out the time until next arrival, and then prints out one of three different messages depending on the time to arrival.

License

Uses the MIT license.

Written with StackEdit.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].