-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflask_app.py
75 lines (61 loc) · 2.54 KB
/
flask_app.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
75
from _operator import itemgetter
from flask import Flask, render_template, send_from_directory
from citibike.util import distance
from citibike.util import bike_util
app = Flask(__name__, template_folder='citibike/templates')
PAS_LATLONG = (40.7436572, -73.9854901)
@app.route("/")
def hello():
return "Hello World!"
@app.route('/static/css/<path:path>')
def send_static_css(path):
return send_from_directory('citibike/static/css', path)
@app.route('/static/js/<path:path>')
def send_static_js(path):
return send_from_directory('citibike/static/js', path)
@app.route('/bootstrap')
def bootstrap():
return render_template('bootstrap.html')
@app.route("/ebike")
def ebike_template():
region_map = bike_util.get_ebikes()
region_status = {}
for region, stations in region_map.items():
bike_count = 0
region_status[region] = []
if stations:
for station, status in stations:
dist = distance.get_distance(PAS_LATLONG, (station.lat, station.lon))
region_status[region].append(
[station.name, status.num_ebikes_available, status.num_bikes_available, dist, region]
)
bike_count += status.num_ebikes_available
region_status[region] = [bike_count] + region_status[region]
else:
region_status[region].append(0)
# for region in region_status:
# region_status[region] = sorted(region_status[region], key=lambda x: x[3])
return render_template('ebike.html', region_status=region_status)
@app.route('/regions')
def regions():
region_status = bike_util.get_region_status()
retstr = ''
no_bikes = ''
bikes = ''
for name in region_status:
status = region_status[name]
if status.num_bikes_available == 0:
no_bikes += "<div>{}: No Bikes Available!</div>".format(name)
else:
bikes += "<div>{}:".format(name)
bikes += '<ul>'
bikes += "<li>Bikes Available: {num} </li>".format(num=status.num_bikes_available)
bikes += "<li>eBikes Available: {num} </li>".format(num=status.num_ebikes_available)
bikes += "<li>Bikes Disabled: {num} </li>".format(num=status.num_bikes_disabled)
bikes += "<li>Docks Available: {num} </li>".format(num=status.num_docks_available)
bikes += "<li>Docks Disabled: {num} </li>".format(num=status.num_docks_disabled)
bikes += '</ul></div>'
retstr = bikes + no_bikes
return retstr
if __name__ == "__main__":
app.run(host='0.0.0.0')