adding in base repo with not implemented functions
This commit is contained in:
1 parent
d9ec582e1e
commit
3225a293a4
4 files changed
+104
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import requests
|
||||
from typing import List
|
||||
|
||||
|
||||
class MTA(object):
|
||||
def __init__(self, api_key: str, train_lines=None, station_ids=None, timing_callbacks=None, alert_callbacks = None):
|
||||
self.api_key = api_key
|
||||
self.train_lines = train_lines if train_lines else []
|
||||
self.station_ids = station_ids if station_ids else []
|
||||
self.timing_callbacks = timing_callbacks if timing_callbacks else []
|
||||
self.alert_callbacks = alert_callbacks if alert_callbacks else []
|
||||
|
||||
def start_updates(self):
|
||||
print("starting updates")
|
||||
raise NotImplementedError("Have not implemented start updates yet")
|
||||
|
||||
async def process_callbacks(self):
|
||||
raise NotImplementedError("Have not implemented callback processing yet")
|
||||
|
||||
|
||||
def add_train_line(self, train_line: str):
|
||||
self.train_lines.append(train_line)
|
||||
|
||||
def remove_train_line(self, train_line: str):
|
||||
self.train_lines.remove(train_line)
|
||||
|
||||
def add_station_id(self, station_id: str):
|
||||
self.station_ids.append(station_id)
|
||||
|
||||
def remove_station_id(self, station_id: str):
|
||||
self.station_ids.remove(station_id)
|
||||
|
||||
def add_callback(self, callback_func):
|
||||
self.timing_callbacks.append(callback_func)
|
||||
|
||||
def remove_callback(self, callback_func):
|
||||
self.timing_callbacks.remove(callback_func)
|
||||
@@ -0,0 +1 @@
|
||||
{"lastUpdated": "2021-05-10T12:34:40-0400", "routeDetails": [{"route": "2", "color": "EE352E", "mode": "subway", "agency": "MTASBWY", "routeId": "MTASBWY_2", "inService": "true", "routeType": "1", "statusDetails": [{"id": "lmm:alert:73533", "statusSummary": "Weekday Service", "statusDescription": "<p>[2] trains run between <b>Wakefield-241 St</b> and <b>Flatbush Av-Brooklyn College</b>.</p>", "priority": 3, "direction": "0", "creationDate": "2021-04-24T07:50:19-0400", "startDate": "2021-05-10T04:01:12-0400", "endDate": null}, {"id": "lmm:alert:73533", "statusSummary": "Weekday Service", "statusDescription": "<p>[2] trains run between <b>Wakefield-241 St</b> and <b>Flatbush Av-Brooklyn College</b>.</p>", "priority": 3, "direction": "1", "creationDate": "2021-04-24T07:50:19-0400", "startDate": "2021-05-10T04:01:12-0400", "endDate": null}]}, {"route": "3", "color": "EE352E", "mode": "subway", "agency": "MTASBWY", "routeId": "MTASBWY_3", "inService": "true", "routeType": "1", "statusDetails": [{"id": "lmm:alert:73541", "statusSummary": "Weekday Service", "statusDescription": "<p>[3] trains run between <b>Harlem-148 St</b> and <b>New Lots Av</b>.</p>", "priority": 3, "direction": "0", "creationDate": "2021-04-24T07:51:06-0400", "startDate": "2021-05-10T04:03:11-0400", "endDate": null}, {"id": "lmm:alert:73541", "statusSummary": "Weekday Service", "statusDescription": "<p>[3] trains run between <b>Harlem-148 St</b> and <b>New Lots Av</b>.</p>", "priority": 3, "direction": "1", "creationDate": "2021-04-24T07:51:06-0400", "startDate": "2021-05-10T04:03:11-0400", "endDate": null}]}, {"route": "6X", "color": "00A65C", "mode": "subway", "agency": "MTASBWY", "routeId": "MTASBWY_6X", "inService": "true", "routeType": "1", "statusDetails": null}, {"route": "1", "color": "EE352E", "mode": "subway", "agency": "MTASBWY", "routeId": "MTASBWY_1", "inService": "true", "routeType": "1", "statusDetails": [{"id": "lmm:alert:73532", "statusSummary": "Weekday Service", "statusDescription": "<p>[1] trains run between \u200c\u200c<b>Van Cortlandt Park-242 St</b> and <b>South Ferry</b>.</p>", "priority": 3, "direction": "1", "creationDate": "2020-12-10T00:59:42-0500", "startDate": "2021-05-10T04:00:51-0400", "endDate": null}, {"id": "lmm:alert:73532", "statusSummary": "Weekday Service", "statusDescription": "<p>[1] trains run between \u200c\u200c<b>Van Cortlandt Park-242 St</b> and <b>South Ferry</b>.</p>", "priority": 3, "direction": "0", "creationDate": "2020-12-10T00:59:42-0500", "startDate": "2021-05-10T04:00:51-0400", "endDate": null}]}, {"route": "S", "color": null, "mode": "subway", "agency": "MTASBWY", "routeId": "MTASBWY_FS", "inService": "true", "routeType": "1", "statusDetails": [{"id": "lmm:alert:73543", "statusSummary": "Weekday Service", "statusDescription": "<p>[FS] trains run between <b>Franklin Av</b> and <b>Prospect Park</b>.</p>", "priority": 3, "direction": "0", "creationDate": "2020-12-08T01:07:08-0500", "startDate": "2021-05-10T04:03:37-0400", "endDate": null}, {"id": "lmm:alert:73543", "statusSummary": "Weekday Service", "statusDescription": "<p>[FS] trains run between <b>Franklin Av</b> and <b>Prospect Park</b>.</p>", "priority": 3, "direction": "1", "creationDate": "2020-12-08T01:07:08-0500", "startDate": "2021-05-10T04:03:37-0400", "endDate": null}]}, {"route": "FX", "color": "FF6319", "mode": "subway", "agency": "MTASBWY", "routeId": "MTASBWY_FX", "inService": "true", "routeType": "1", "statusDetails": null}, {"route": "W", "color": "FCCC0A", "mode": "subway", "agency": "MTASBWY", "routeId": "MTASBWY_W", "inService": "true", "routeType": "1", "statusDetails": [{"id": "lmm:alert:73555", "statusSummary": "Weekday Service", "statusDescription": "<p>[W] trains run between <b>Astoria-Ditmars Blvd</b> and <b>Whitehall St-South Ferry</b>.</p><p style=\"line-height: 1.4375;\">Departing <b>Astoria-Ditmars Blvd</b> from 6:13 AM to 9:26 PM</p><p style=\"line-height: 1.4375;\">Departing <b>Whitehall St-South Ferry</b> from 7:06 AM to 10:14 PM.</p><p style=\"line-height: 1.4375;\">[W] trains do not operate late nights and weekends, take [N] or [R] service instead.</p>", "priority": 3, "direction": "0", "creationDate": "2021-04-21T08:17:11-0400", "startDate": "2021-05-10T04:58:38-0400", "endDate": null}, {"id": "lmm:alert:73555", "statusSummary": "Weekday Service", "statusDescription": "<p>[W] trains run between <b>Astoria-Ditmars Blvd</b> and <b>Whitehall St-South Ferry</b>.</p><p style=\"line-height: 1.4375;\">Departing <b>Astoria-Ditmars Blvd</b> from 6:13 AM to 9:26 PM</p><p style=\"line-height: 1.4375;\">Departing <b>Whitehall St-South Ferry</b> from 7:06 AM to 10:14 PM.</p><p style=\"line-height: 1.4375;\">[W] trains do not operate late nights and weLine truncated
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
from mta import MTA
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
||||
async def mta_callback(data):
|
||||
print("We are inside of hte call back now boizzzz")
|
||||
print(data)
|
||||
|
||||
|
||||
api_key = os.getenv('MTA_API_KEY', '')
|
||||
mtaController = MTA(api_key)
|
||||
mtaController.add_callback(mta_callback)
|
||||
|
||||
mtaController.start_updates()
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
import requests
|
||||
import os
|
||||
import json
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from pprint import pprint
|
||||
|
||||
load_dotenv()
|
||||
|
||||
#endpoint definitions - should be loaded form the env if possible, woudl make it easily maintaine from docker
|
||||
ACE_ENDPOINT = "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/nyct%2Fgtfs-ace"
|
||||
SUBWAY_ALERTS = "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/camsys%2Fsubway-alerts"
|
||||
SUBWAY_ALERTS_JSON = "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/camsys%2Fsubway-status.json"
|
||||
|
||||
|
||||
def create_api_call_header(api_key):
|
||||
return {
|
||||
"x-api-key":api_key
|
||||
}
|
||||
|
||||
|
||||
def test_api_calls():
|
||||
print("Testing the api")
|
||||
api_key = os.getenv('MTA_API_KEY', '')
|
||||
r = requests.get(
|
||||
SUBWAY_ALERTS_JSON,
|
||||
headers=create_api_call_header(api_key)
|
||||
)
|
||||
print(r)
|
||||
print(r.status_code)
|
||||
pprint(r.json())
|
||||
with open("mta_status_alerts.json", "w+") as f:
|
||||
f.write(json.dumps(r.json()))
|
||||
|
||||
|
||||
|
||||
r = requests.get(
|
||||
ACE_ENDPOINT,
|
||||
headers=create_api_call_header(api_key)
|
||||
)
|
||||
print(r)
|
||||
print(r.status_code)
|
||||
print(r.content)
|
||||
|
||||
# alerts_data = json.loads()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_api_calls()
|
||||
Reference in new issue
Block a user