From dfdffda31e2c5af575a69a293d6b04987d2798c5 Mon Sep 17 00:00:00 2001 From: Lucas Date: Sun, 18 Jul 2021 14:04:17 -0400 Subject: [PATCH] Adding reqs --- requirements.txt | 21 ++++++++++ server.py | 71 ++++++++++++++++++++++------------ server_test.py | 0 templates/layouts/index.html | 11 ++++++ templates/static/css/style.css | 5 +++ test_closures.py | 9 ----- 6 files changed, 83 insertions(+), 34 deletions(-) create mode 100644 requirements.txt delete mode 100644 server_test.py delete mode 100644 test_closures.py diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..009318e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,21 @@ +certifi==2020.12.5 +chardet==4.0.0 +click==8.0.1 +colorama==0.4.4 +Flask==2.0.1 +gtfs-realtime-bindings==0.0.7 +idna==2.10 +itsdangerous==2.0.1 +Jinja2==3.0.1 +MarkupSafe==2.0.1 +numpy==1.21.0 +pandas==1.3.0 +protobuf==3.16.0 +protobuf3-to-dict==0.1.5 +python-dateutil==2.8.1 +python-dotenv==0.17.1 +pytz==2021.1 +requests==2.25.1 +six==1.16.0 +urllib3==1.26.4 +Werkzeug==2.0.1 diff --git a/server.py b/server.py index 1596fd9..03cb697 100644 --- a/server.py +++ b/server.py @@ -3,6 +3,7 @@ import threading from flask import Flask, jsonify, render_template, request from mta_manager import MTA from pprint import pprint +import pandas as pd app = Flask(__name__) app.secret_key = "SuperSecretDontEvenTryToGuessMeGGEZNoRe" @@ -11,10 +12,15 @@ app._static_folder = os.path.abspath("templates/static/") subway_data = {} +stops = pd.read_csv("stops.txt") + + @app.route("/", methods=["GET"]) def index(): - title = "Create the input image" - return render_template("layouts/index.html", title=title) + # TODO: Shove this into a sqlite database + station_names = sorted(list(set(stops["stop_name"].to_list()))) + print(station_names) + return render_template("layouts/index.html", station_names=station_names) @app.route("/mta_data", methods=["POST"]) @@ -24,41 +30,56 @@ def get_mta_data(): subway_data ) + @app.route("/stops", methods=["GET"]) def get_routes(): return jsonify() +@app.route("/get_stop_id/", methods=["GET"]) +def get_stop_id(stop_name): + print(stop_name) + rows = stops.loc[stops["stop_name"] == stop_name] + print(rows) + return str(rows) + + + +def ack(): + print('message was received!') + + +class threadWrapper(threading.Thread): + def __init__(self, run, controller): + threading.Thread.__init__(self) + self.run = run + self.controller = controller + + def run(self): + self.run() + + +async def mta_callback(routes): + global subway_data + # TODO: Do away with this and throw it into websockets + subway_data = mtaController.convert_routes_to_station_first(routes) + + +def start_mta(): + mtaController.add_callback(mta_callback) + mtaController.start_updates() + + if __name__ == "__main__": api_key = os.getenv('MTA_API_KEY', '') mtaController = MTA( + # TODO: Update to only work with station names - need to be able to transfer the station names to train lines - + # maybe with polling the station ids to see what train lines come up? api_key, ["A", "C", "E", "1", "2", "3"], ["127S", "127N", "A27N", "A27S"] ) - - - async def mta_callback(routes): - global subway_data - # TODO: Do away with this and throw it into websockets - subway_data = 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() - - threadLock = threading.Lock() - threads = [threadWrapper(start_mta)] + threads = [threadWrapper(start_mta, mtaController)] for t in threads: t.start() diff --git a/server_test.py b/server_test.py deleted file mode 100644 index e69de29..0000000 diff --git a/templates/layouts/index.html b/templates/layouts/index.html index dc2bcf5..d3b86b9 100644 --- a/templates/layouts/index.html +++ b/templates/layouts/index.html @@ -27,6 +27,17 @@
diff --git a/templates/static/css/style.css b/templates/static/css/style.css index c8be136..296c5e1 100644 --- a/templates/static/css/style.css +++ b/templates/static/css/style.css @@ -18,6 +18,11 @@ float: right; } +.dropdown-menu { + max-height: 280px; + overflow-y: auto; +} + @media screen and (max-width: 1000px) { .site-title { diff --git a/test_closures.py b/test_closures.py deleted file mode 100644 index bc89e6e..0000000 --- a/test_closures.py +++ /dev/null @@ -1,9 +0,0 @@ -import requests - - -headers = { - -} -r = requests.get("http://localhost:58381/api/closures?BlockId=B445205") - -