forked from jamadeo/traintime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
executable file
·52 lines (39 loc) · 1.19 KB
/
server.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
#!/usr/bin/python
import os
import sys
# Needs to execute before any other imports
import google
vendor_dir = os.path.join(os.path.dirname(__file__), 'vendor')
google.__path__.append(os.path.join(vendor_dir, 'google'))
sys.path.insert(0, vendor_dir)
import web
import time
import model
import json
from web import form
urls = (
'/', 'index',
'/trains/?', 'index',
'/trains/(.+)', 'traintime'
)
render = web.template.render('templates')
app_config = json.load(open('gtfs.config'))
api_key = json.load(open('mta_api_key'))['api_key']
model.initialize(api_key, app_config['gtfs_directory'], app_config['cache_max_age'])
class index:
def GET(self):
return render.index(sorted(model.get_stops(), key=lambda stop:stop[1]))
def POST(self):
user_input = web.input(stations=[])
raise web.seeother('/trains/' + ','.join(user_input.stations))
class traintime:
def GET(self, train_stops):
return render.arrivals(model.get_trains_for_stops(train_stops.split(',')))
class styles:
def GET(self, style):
f = open(style)
style_str = f.read()
f.close()
return style_str
app = web.application(urls, globals())
app = app.gaerun()