Moving mta_manager logic into its own package - will most likely mvoe to its own repo shortly
This commit is contained in:
3
mta_manager/__init__.py
Normal file
3
mta_manager/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from .mta import *
|
||||||
|
from .route import *
|
||||||
|
from .stop import *
|
||||||
@@ -4,7 +4,7 @@ import json
|
|||||||
|
|
||||||
from google.transit import gtfs_realtime_pb2
|
from google.transit import gtfs_realtime_pb2
|
||||||
from protobuf_to_dict import protobuf_to_dict
|
from protobuf_to_dict import protobuf_to_dict
|
||||||
from route import get_route_from_dict
|
from .route import get_route_from_dict
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
|
|
||||||
@@ -24,7 +24,6 @@ class MTA(object):
|
|||||||
with open(endpoints_file, "r") as f:
|
with open(endpoints_file, "r") as f:
|
||||||
self.endpoints = json.load(f)
|
self.endpoints = json.load(f)
|
||||||
self.set_valid_endpoints()
|
self.set_valid_endpoints()
|
||||||
# TODO: filter out anything from a train line we are not searching for
|
|
||||||
|
|
||||||
def set_valid_endpoints(self):
|
def set_valid_endpoints(self):
|
||||||
self.valid_endpoints = {}
|
self.valid_endpoints = {}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from stop import get_stop_from_dict
|
from .stop import get_stop_from_dict
|
||||||
|
|
||||||
|
|
||||||
def get_route_from_dict(obj):
|
def get_route_from_dict(obj):
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
from flask import Flask, jsonify, render_template, request
|
from flask import Flask, jsonify, render_template, request
|
||||||
from mta import MTA
|
from mta_manager import MTA
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|||||||
49
testing.py
49
testing.py
@@ -1,49 +0,0 @@
|
|||||||
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