adding in start time to the PI MTA display
This commit is contained in:
33
server.py
33
server.py
@@ -17,17 +17,7 @@ app._static_folder = os.path.abspath("templates/static/")
|
|||||||
stops = pd.read_csv("stops.txt")
|
stops = pd.read_csv("stops.txt")
|
||||||
stop_ids = ["127S", "127N", "A27N", "A27S"]
|
stop_ids = ["127S", "127N", "A27N", "A27S"]
|
||||||
|
|
||||||
|
start_time = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
||||||
@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"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def link_to_station(data):
|
def link_to_station(data):
|
||||||
@@ -44,6 +34,23 @@ def link_to_station(data):
|
|||||||
return linked_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"])
|
@app.route("/mta_data", methods=["POST"])
|
||||||
def get_mta_data():
|
def get_mta_data():
|
||||||
global subway_data
|
global subway_data
|
||||||
@@ -73,10 +80,10 @@ def get_stop_id():
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
api_key = os.getenv('MTA_API_KEY', '')
|
api_key = os.getenv('MTA_API_KEY', '')
|
||||||
|
|
||||||
|
|
||||||
old_data = None
|
old_data = None
|
||||||
last_updated = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
last_updated = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
||||||
|
|
||||||
|
|
||||||
async def mta_callback(routes):
|
async def mta_callback(routes):
|
||||||
global subway_data, old_data, last_updated
|
global subway_data, old_data, last_updated
|
||||||
subway_data = link_to_station(mtaController.convert_routes_to_station_first(routes))
|
subway_data = link_to_station(mtaController.convert_routes_to_station_first(routes))
|
||||||
@@ -106,6 +113,7 @@ if __name__ == "__main__":
|
|||||||
)
|
)
|
||||||
mtaController.add_callback(mta_callback)
|
mtaController.add_callback(mta_callback)
|
||||||
|
|
||||||
|
|
||||||
def start_mta():
|
def start_mta():
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
@@ -113,6 +121,7 @@ if __name__ == "__main__":
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
app.logger.info(f"Exception found in update function - {e}")
|
app.logger.info(f"Exception found in update function - {e}")
|
||||||
|
|
||||||
|
|
||||||
threadLock = threading.Lock()
|
threadLock = threading.Lock()
|
||||||
threads = [threadWrapper(start_mta)]
|
threads = [threadWrapper(start_mta)]
|
||||||
|
|
||||||
|
|||||||
@@ -31,10 +31,18 @@
|
|||||||
Pi MTA Display!
|
Pi MTA Display!
|
||||||
</h1>
|
</h1>
|
||||||
</a>
|
</a>
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
<h3>
|
<h3>
|
||||||
Last Updated: <span id="last_updated"></span>
|
Last Updated: <span id="last_updated"></span>
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<h3 style="float:right">
|
||||||
|
Started: <span style="float:right" id="start_time"></span>
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<div id="station_1">
|
<div id="station_1">
|
||||||
<nav class="navbar navbar-dark bg-dark">
|
<nav class="navbar navbar-dark bg-dark">
|
||||||
|
|||||||
@@ -1,14 +1,6 @@
|
|||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
|
||||||
const interval = setInterval(function () {
|
function updateStationData(station) {
|
||||||
updateData($('#station_1'))
|
|
||||||
}, 5000);
|
|
||||||
const interval2 = setInterval(function () {
|
|
||||||
updateData($('#station_2'))
|
|
||||||
}, 6000);
|
|
||||||
|
|
||||||
function updateData(station) {
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: '/mta_data',
|
url: '/mta_data',
|
||||||
@@ -24,6 +16,24 @@ $(document).ready(function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function updateStartTime() {
|
||||||
|
$.ajax({
|
||||||
|
type: "get",
|
||||||
|
url: '/start_time',
|
||||||
|
// contentType: "application/json",
|
||||||
|
// dataType: "json",
|
||||||
|
async: true,
|
||||||
|
// data: JSON.stringify({"station": station.find('.station-name:first').get(0).innerText}, null, '\t'),
|
||||||
|
success: function (data, text) {
|
||||||
|
console.log("GETTING TIME")
|
||||||
|
console.log(data);
|
||||||
|
$("#start_time").text(data)
|
||||||
|
},
|
||||||
|
error: function (request, status, error) {
|
||||||
|
alert(request.responseText);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function updateStation(station, data) {
|
function updateStation(station, data) {
|
||||||
updateDirections(station, data, "North");
|
updateDirections(station, data, "North");
|
||||||
@@ -71,20 +81,25 @@ $(document).ready(function () {
|
|||||||
console.log($(listItem))
|
console.log($(listItem))
|
||||||
$(listItem).hide()
|
$(listItem).hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function imageExists(image_url) {
|
function imageExists(image_url) {
|
||||||
|
|
||||||
var http = new XMLHttpRequest();
|
var http = new XMLHttpRequest();
|
||||||
|
|
||||||
http.open('HEAD', image_url, false);
|
http.open('HEAD', image_url, false);
|
||||||
http.send();
|
http.send();
|
||||||
|
|
||||||
return http.status != 404;
|
return http.status != 404;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const interval = setInterval(function () {
|
||||||
|
updateStationData($('#station_1'))
|
||||||
|
}, 5000);
|
||||||
|
const interval2 = setInterval(function () {
|
||||||
|
updateStationData($('#station_2'))
|
||||||
|
}, 6000);
|
||||||
|
updateStartTime();
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function setStation(ele) {
|
function setStation(ele) {
|
||||||
|
|||||||
Reference in New Issue
Block a user