-
Notifications
You must be signed in to change notification settings - Fork 0
/
mbtaonbus.py
75 lines (67 loc) · 2.84 KB
/
mbtaonbus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# mbtaonbus
# preds.py
# Created by M. Haynes
# Late July 2018 & January 2019 (Flask)
#
import main_functions as mf
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
# Main index page returns a list of active buses to choose from for demo:
def index():
return render_template('buslist.html',veh_list=mf.getvehicles())
@app.route("/preds/<string:bus>/")
# The main page with bus current route info and prediction grid with map:
def preds(bus):
veh_data = mf.getbasicdata(bus)
if veh_data is not None:
# Go get the predictions, shape and alerts and store in a data dictionary:
data_dict = {"veh_data": veh_data,
"pred_data": mf.getpredictions(veh_data["trip_id"]),
"shape_data": mf.getshape(veh_data["shape_id"]),
"alert_data": mf.getalerts(veh_data["route_id"]),
"map_data": mf.getmapboxkey(),
"stop_data": mf.getstops(veh_data["trip_id"])
}
# Should probably test for prediction data as well before continuing:
return render_template('preds.html',data=data_dict)
else:
# Bus not in service, return the no predictions page.
return render_template('nopreds.html',bus=bus)
@app.route("/preds-dark/<string:bus>/")
# The main page with bus current route info and prediction grid with map:
def preds_dark(bus):
veh_data = mf.getbasicdata(bus)
if veh_data is not None:
# Go get the predictions, shape and alerts and store in a data dictionary:
data_dict = {"veh_data": veh_data,
"pred_data": mf.getpredictions(veh_data["trip_id"]),
"shape_data": mf.getshape(veh_data["shape_id"]),
"alert_data": mf.getalerts(veh_data["route_id"]),
"map_data": mf.getmapboxkey(),
"stop_data": mf.getstops(veh_data["trip_id"])
}
# Should probably test for prediction data as well before continuing:
return render_template('preds-dark.html',data=data_dict)
else:
# Bus not in service, return the no predictions page.
return render_template('nopreds.html',bus=bus)
# Not sure if this is required or not for the main Flask application:
if __name__ == "__main__":
app.run()
#mbtaonbus
#On-bus prediction screen prototype using MBTA API. {not affiliated with the MBTA}
# Copyright (C) 2019 MICHAEL HAYNES
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.