-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
85 lines (65 loc) · 1.79 KB
/
app.py
File metadata and controls
85 lines (65 loc) · 1.79 KB
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
76
77
78
79
80
81
82
83
84
85
import json
import requests
from bottle import Bottle, run, debug, static_file
# DEV
import cherrypy
cherrypy.config.update({"log.screen": True})
# ENDDEV
app = Bottle()
busAPI = "http://www3.septa.org/api/TransitView/index.php?route="
root = "assets"
@app.route('/about')
def about():
return static_file("/about.html", root)
@app.route('/')
def index():
return static_file("/index.html", root)
@app.route('/debugger')
def debugger():
return static_file("/debugger.html", root)
@app.error(404)
def error404(error):
return "Sorry! Nothing here!"
@app.route("/busdata/<route>")
def busdata(route):
r = requests.get(busAPI + route)
parsed_json = json.loads(r.content)
features = []
for bus in parsed_json["bus"]:
direction = bus["Direction"]
icon = "bus-NE"\
if direction == "NorthBound" or direction == "EastBound"\
else "bus-SW"
point = {
"type": "Point",
"coordinates": map(float, [bus["lng"], bus["lat"]])
}
properties = {
"direction": direction,
"id": bus["label"],
"destination": bus["destination"],
"route": route,
"icon": icon,
"block": bus["BlockID"],
"lastUpdated": bus["Offset_sec"]
}
feature = {
"type": "Feature",
"geometry": point,
"properties": properties
}
features.append(feature)
feature_collection = {"type": "FeatureCollection", "features": features}
return json.dumps(feature_collection)
# DEV
@app.route('/<filepath:path>')
def static(filepath):
return static_file(filepath, root)
# ENDDEV
# BUILD
# application = app
# ENDBUILD
# DEV
debug(True)
run(app, reloader=True, server="cherrypy", port=8000)
# ENDDEV