-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapper_app.py
30 lines (25 loc) · 883 Bytes
/
mapper_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
#!/usr/bin/env python
# Kyle Fitzsimmons, 2014
from flask import Flask, render_template, jsonify, json
from werkzeug.contrib.cache import SimpleCache
from urllib2 import HTTPError
import gtfs_database as gdb
app = Flask(__name__)
cache = SimpleCache()
@app.route("/")
def hello():
routes = gdb.get_trips_now()
route_nums = sorted(routes.keys())
cache.set('routes', routes, timeout=3*60)
return render_template('index.html', active_routes=route_nums)
@app.route("/route<int:route>")
def get_geojson(route):
available_routes = cache.get('routes')
if not available_routes:
available_routes = gdb.get_trips_now()
geojson = gdb.route_geojson(routes=available_routes, selected_route=route)
if not geojson:
return ('', 204) # HTTP no content
return jsonify(geojson)
if __name__ == "__main__":
app.run(host='0.0.0.0', debug=True)