adding in base repo with not implemented functions
This commit is contained in:
37
mta.py
Normal file
37
mta.py
Normal file
@@ -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)
|
||||||
1
mta_status_alerts.json
Normal file
1
mta_status_alerts.json
Normal file
File diff suppressed because one or more lines are too long
17
mta_test.py
Normal file
17
mta_test.py
Normal file
@@ -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
testing.py
Normal file
49
testing.py
Normal file
@@ -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