adding update time very hastily to the top right
This commit is contained in:
@@ -3,6 +3,7 @@ certifi==2020.12.5
|
||||
chardet==4.0.0
|
||||
click==8.0.1
|
||||
colorama==0.4.4
|
||||
deepdiff==5.5.0
|
||||
dnspython==1.16.0
|
||||
Flask==2.0.1
|
||||
greenlet==1.1.0
|
||||
@@ -13,6 +14,7 @@ itsdangerous==2.0.1
|
||||
Jinja2==3.0.1
|
||||
MarkupSafe==2.0.1
|
||||
numpy==1.21.0
|
||||
ordered-set==4.0.2
|
||||
pandas==1.3.0
|
||||
protobuf==3.16.0
|
||||
protobuf3-to-dict==0.1.5
|
||||
|
||||
41
server.py
41
server.py
@@ -1,12 +1,12 @@
|
||||
import logging
|
||||
import os
|
||||
import threading
|
||||
|
||||
from flask import Flask, jsonify, render_template, request, abort
|
||||
from mta_manager import MTA
|
||||
import pandas as pd
|
||||
|
||||
from deepdiff import DeepDiff
|
||||
from datetime import datetime
|
||||
from dotenv import load_dotenv
|
||||
from flask import Flask, jsonify, render_template, request, abort
|
||||
from mta_manager import MTA
|
||||
|
||||
load_dotenv()
|
||||
|
||||
@@ -49,8 +49,10 @@ def get_mta_data():
|
||||
global subway_data
|
||||
station = request.json["station"]
|
||||
if station in subway_data:
|
||||
mta_data = subway_data[station]
|
||||
mta_data["LastUpdated"] = subway_data["LastUpdated"]
|
||||
return jsonify(
|
||||
subway_data[station]
|
||||
mta_data
|
||||
)
|
||||
else:
|
||||
abort(404)
|
||||
@@ -71,16 +73,20 @@ def get_stop_id():
|
||||
if __name__ == "__main__":
|
||||
api_key = os.getenv('MTA_API_KEY', '')
|
||||
|
||||
mtaController = MTA(
|
||||
api_key,
|
||||
["A", "C", "E", "1", "2", "3"],
|
||||
["127S", "127N", "A27N", "A27S"]
|
||||
)
|
||||
|
||||
old_data = None
|
||||
last_updated = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
||||
|
||||
async def mta_callback(routes):
|
||||
global subway_data
|
||||
global subway_data, old_data, last_updated
|
||||
subway_data = link_to_station(mtaController.convert_routes_to_station_first(routes))
|
||||
subway_data["LastUpdated"] = last_updated
|
||||
if old_data is None:
|
||||
old_data = subway_data
|
||||
data_diff = DeepDiff(old_data, subway_data, ignore_order=True)
|
||||
if data_diff != {}:
|
||||
old_data = subway_data
|
||||
last_updated = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
||||
app.logger.info(f"Updated Subway Data - {subway_data}")
|
||||
|
||||
|
||||
@@ -93,15 +99,20 @@ if __name__ == "__main__":
|
||||
self.run()
|
||||
|
||||
|
||||
mtaController = MTA(
|
||||
api_key,
|
||||
["A", "C", "E", "1", "2", "3"],
|
||||
["127S", "127N", "A27N", "A27S"]
|
||||
)
|
||||
mtaController.add_callback(mta_callback)
|
||||
|
||||
def start_mta():
|
||||
mtaController.add_callback(mta_callback)
|
||||
while True:
|
||||
try:
|
||||
mtaController.start_updates()
|
||||
except Exception as e:
|
||||
app.logger.info(f"Exception found in update function - {e}")
|
||||
|
||||
|
||||
threadLock = threading.Lock()
|
||||
threads = [threadWrapper(start_mta)]
|
||||
|
||||
@@ -109,10 +120,8 @@ 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= False, port=5000)
|
||||
|
||||
# Wait for all threads to complete
|
||||
for t in threads:
|
||||
t.join()
|
||||
print("Exiting Main Thread")
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
src="https://code.jquery.com/jquery-3.6.0.min.js"
|
||||
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
|
||||
crossorigin="anonymous"></script>
|
||||
<script src="/static/js/DataRequests.js"></script>
|
||||
<script src="/static/js/MtaData.js"></script>
|
||||
|
||||
<title>Hello, world!</title>
|
||||
<title>Pi MTA Display!</title>
|
||||
</head>
|
||||
<body class="dark">
|
||||
<nav class="navbar navbar-dark bg-dark py-2">
|
||||
@@ -31,6 +31,9 @@
|
||||
Pi MTA Display!
|
||||
</h1>
|
||||
</a>
|
||||
<h3>
|
||||
Last Updated: <span id="last_updated"></span>
|
||||
</h3>
|
||||
</div>
|
||||
</nav>
|
||||
<div id="station_1">
|
||||
@@ -205,8 +208,5 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -28,6 +28,12 @@ $(document).ready(function () {
|
||||
function updateStation(station, data) {
|
||||
updateDirections(station, data, "North");
|
||||
updateDirections(station, data, "South");
|
||||
updateTime(data["LastUpdated"])
|
||||
}
|
||||
|
||||
function updateTime(lastUpdated){
|
||||
console.log(lastUpdated)
|
||||
$("#last_updated").text(lastUpdated)
|
||||
}
|
||||
|
||||
function updateDirections(station, data, direction) {
|
||||
Reference in New Issue
Block a user