From ec92d1cddfac9558411097ba7dfbecf90cba4543 Mon Sep 17 00:00:00 2001 From: Lucas Date: Sun, 7 Nov 2021 15:51:27 -0500 Subject: [PATCH] adding in start time to the PI MTA display --- server.py | 35 +++++++++++++++---------- templates/layouts/index.html | 16 +++++++++--- templates/static/js/MtaData.js | 47 ++++++++++++++++++++++------------ 3 files changed, 65 insertions(+), 33 deletions(-) diff --git a/server.py b/server.py index 4d0a0be..1fecfd9 100644 --- a/server.py +++ b/server.py @@ -17,17 +17,7 @@ app._static_folder = os.path.abspath("templates/static/") stops = pd.read_csv("stops.txt") stop_ids = ["127S", "127N", "A27N", "A27S"] - -@app.route("/", methods=["GET"]) -def index(): - # TODO: Shove this into a sqlite database - station_names = sorted(list(set(stops["stop_name"].to_list()))) - return render_template( - "layouts/index.html", - station_names=station_names, - station_1="42 St-Port Authority Bus Terminal", - station_2="Times Sq-42 St" - ) +start_time = datetime.now().strftime("%d/%m/%Y %H:%M:%S") def link_to_station(data): @@ -44,6 +34,23 @@ def link_to_station(data): return linked_data +@app.route("/", methods=["GET"]) +def index(): + # TODO: Shove this into a sqlite database + station_names = sorted(list(set(stops["stop_name"].to_list()))) + return render_template( + "layouts/index.html", + station_names=station_names, + station_1="42 St-Port Authority Bus Terminal", + station_2="Times Sq-42 St" + ) + + +@app.route("/start_time", methods=["GET"]) +def get_start_time(): + return start_time + + @app.route("/mta_data", methods=["POST"]) def get_mta_data(): global subway_data @@ -73,10 +80,10 @@ def get_stop_id(): if __name__ == "__main__": api_key = os.getenv('MTA_API_KEY', '') - old_data = None last_updated = datetime.now().strftime("%d/%m/%Y %H:%M:%S") + async def mta_callback(routes): global subway_data, old_data, last_updated subway_data = link_to_station(mtaController.convert_routes_to_station_first(routes)) @@ -106,6 +113,7 @@ if __name__ == "__main__": ) mtaController.add_callback(mta_callback) + def start_mta(): while True: try: @@ -113,6 +121,7 @@ if __name__ == "__main__": except Exception as e: app.logger.info(f"Exception found in update function - {e}") + threadLock = threading.Lock() threads = [threadWrapper(start_mta)] @@ -120,7 +129,7 @@ if __name__ == "__main__": t.start() debug = os.getenv("DEBUG", 'False').lower() in ('true', '1', 't') - app.run(host="localhost", debug= True, port=5000) + app.run(host="localhost", debug=True, port=5000) for t in threads: t.join() diff --git a/templates/layouts/index.html b/templates/layouts/index.html index 8da0a50..84d713e 100644 --- a/templates/layouts/index.html +++ b/templates/layouts/index.html @@ -31,10 +31,18 @@ Pi MTA Display! -

- Last Updated:   -

- +
+
+

+ Last Updated:   +

+
+
+

+ Started:   +

+
+