adding in start time to the PI MTA display
This commit is contained in:
35
server.py
35
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()
|
||||
|
||||
Reference in New Issue
Block a user