jonthornton/MTAPI
关于
为 MTA 纽约市地铁实时数据源提供 JSON 代理服务
系统与基础设施实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文MTA Realtime API JSON Proxy
MTAPI is a small HTTP server that converts the MTA's realtime subway feed from Protocol Buffers/GTFS to JSON. The app also adds caching and makes it possible to retrieve information by location and train line.
Active Development
This project is under active development and any part of the API may change. Feedback is very welcome.
Running the server
MTAPI is a Flask app designed to run under Python 3.12+. Dependencies are managed with uv.
- Create a
settings.cfgfile. A sample is provided assettings.cfg.sample. - Install dependencies. uv will create a virtual environment and install the pinned versions from
uv.lock.$ uv sync
To include the test dependencies, useuv sync --group devinstead. - Run the server
$ uv run python app.py
If your configuration is named something other than settings.cfg, set the MTAPI_SETTINGS env variable to your configuration path.
For deployment, install the deploy dependency group and run the app under gunicorn:
$ uv sync --group deploy
$ uv run gunicorn app:app
This app makes use of Python threads to refresh data in the background. Each gunicorn worker maintains its own cache and refresh thread, so running multiple workers multiplies the number of requests made to the MTA API. If running under uWSGI instead, include the --enable-threads flag.
Endpoints
Endpoints to retrieve train data and sample input and output are listed here.
Settings
STATIONS_FILE (required)
Path to the JSON file containing station information. See Generating a Stations File for more info.
default: NoneCROSS_ORIGIN
Add CORS headers to the HTTP output.
default: "*" when in debug mode, None otherwiseMAX_TRAINS
Limits the number of trains that will be listed for each station.
default: 10MAX_MINUTES
Limits how far in advance train information will be listed.
default: 30CACHE_SECONDS
How frequently the app will request fresh data from the MTA API.
default: 60THREADED
Enable background data refresh. This will prevent requests from hanging while new data is retrieved from the MTA API.
default: TrueDEBUG
Standard Flask option. Will enabled enhanced logging and wildcard CORS headers.
default: False
Generating a Stations File
The MTA provides several static data files about the subway system but none include canonical information about each station. MTAPI includes a script that will parse the stops.txt and transfers.txt datasets provided by the MTA and attempt to group the different train stops into subway stations. MTAPI will use this JSON file for station names and locations. The grouping is not perfect and editing the resulting files is encouraged.
Usage:
$ uv run python scripts/make_stations_csv.py stops.txt transfers.txt > stations.csv
# edit groupings in stations.csv
$ uv run python scripts/make_stations_json.py stations.csv > stations.json
# edit names in stations.json
Help
Submit a GitHub Issues request.
Projects
Here are some projects that use MTAPI.
License
The project is made available under the MIT license.
探索相关项目
加载中…