The object defined in mtaGTFS allows the user to easily pull and analyze data from the NYC MTA site. This currently includes the 1, 2, 3, 4, 5, 6, S and SIR lines.
It helps parse the GTFS file provided by the MTA. In order to obtain the data, you must first register for an api key. More information on the feeds can be found here on the mta website.
To use the object you must include mtaGTFS.py
along with protobuf_json.py
and nyct_subway_pb2.py`. This object also depends on functionality provided by the following packages:
- google.transit
- pandas
- numpy
Sqlalchemy is required for some specific functions, but not necessary for the object to function properly
See mtaGTFS.py
for details. Import mtaGTFS.py and create a a new object with:
new_object = mtaGTFS(subway_group = "irt", api_key='*************')
subway_group can be either 'irt', 'l', or 'sir' for each train type. Once the object is loaded the enrouteTrains, scheduledStops, and trainIds can be accessed as properties of new_object. The feeds can be updated with the updateFeed method.
- Install mysql
- create a user
- run the mysql/model_generation_script.sql
- Grant the mta_user all privilages: GRANT ALL PRIVILEGES ON mta_trains.* to 'mta_user'@'%' identified by 'userpassword';
- Open up your mysql database to remote connections This probably involves updating the bind_address
- Write the stops.txt file to the stops TABLE
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt
Run the following command in the working directory
bash protobuf/compile_protobuf.sh
This will download the needed files and compile them for use in python.