Adding in full MTA api.

* Added in support for station search, route specific search, and several time limiting functions
Added in functional backend in flask
* starts flask app
* starts MTA app on another thread
* serves basic webpage which pull subway data from flask backend on button press.
This commit is contained in:
Lucas Oskorep
2021-06-15 19:36:33 -04:00
parent 3225a293a4
commit 103de4bc14
12 changed files with 14284 additions and 20 deletions

View File

@@ -1,17 +1,59 @@
import os
from dotenv import load_dotenv
from mta import MTA
import threading
import time
from time import sleep
from pprint import pprint
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 = MTA(
api_key,
["A", "C", "E", "1", "2", "3"],
["127S", "127N", "A27N", "A27S"]
)
mtaController.start_updates()
async def mta_callback(routes):
print("We are inside of the call back now")
print(len(routes))
pprint(mtaController.convert_routes_to_station_first(routes))
class threadWrapper(threading.Thread):
def __init__(self, run):
threading.Thread.__init__(self)
self.run = run
def run(self):
self.run()
def start_mta():
mtaController.add_callback(mta_callback)
mtaController.start_updates()
def stop_mta():
sleep(10)
mtaController.stop_updates()
threadLock = threading.Lock()
threads = []
# Create new threads
thread1 = threadWrapper(start_mta)
thread2 = threadWrapper(stop_mta)
thread1.start()
thread2.start()
# Add threads to thread list
threads.append(thread1)
threads.append(thread2)
# Wait for all threads to complete
for t in threads:
t.join()
print ("Exiting Main Thread")