merged server.py

This commit is contained in:
Lucas Oskorep
2021-10-09 19:38:23 -04:00
2 changed files with 8 additions and 5 deletions

View File

@@ -35,6 +35,7 @@ class MTA(object):
def start_updates(self):
print("starting updates")
raise Exception("Testing failure case")
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(self._get_updates())

View File

@@ -1,9 +1,9 @@
import logging
import os
import threading
from flask import Flask, jsonify, render_template, request, abort
from mta_manager import MTA
from pprint import pprint
import pandas as pd
from dotenv import load_dotenv
@@ -63,11 +63,8 @@ def get_routes():
@app.route("/get_stop_id", methods=["POST"])
def get_stop_id():
print(request.json)
stop_name = request.json["stop_name"]
print(stop_name)
rows = stops.loc[stops["stop_name"] == stop_name]
print(rows)
return jsonify({"station_changed": True})
@@ -98,7 +95,11 @@ if __name__ == "__main__":
def start_mta():
mtaController.add_callback(mta_callback)
mtaController.start_updates()
while True:
try:
mtaController.start_updates()
except Exception as e:
logging.info(f"Exception found in update function - {e}")s
threadLock = threading.Lock()
@@ -110,6 +111,7 @@ if __name__ == "__main__":
debug = os.getenv("DEBUG", 'False').lower() in ('true', '1', 't')
app.run(host="localhost", debug= False, port=5000)
# Wait for all threads to complete
for t in threads:
t.join()