-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmunistop.py
40 lines (33 loc) · 1.33 KB
/
munistop.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
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
import os
from google.appengine.ext.webapp import template
import nextbus
from django.utils.simplejson import JSONEncoder
import datetime
class RoutesController(webapp.RequestHandler):
def get(self):
routes = nextbus.scrapeRoutes()
self.response.out.write(JSONEncoder().encode(routes))
class DirectionsController(webapp.RequestHandler):
def get(self, route):
directions = nextbus.scrapeDirections(route)
self.response.out.write(JSONEncoder().encode(directions))
class StopsController(webapp.RequestHandler):
def get(self, route, direction):
stops = nextbus.scrapeStops(route, direction)
self.response.out.write(JSONEncoder().encode(stops))
class TimeController(webapp.RequestHandler):
def get(self, route, direction, stop):
times = nextbus.scrapeTime(route, direction, stop)
self.response.out.write(JSONEncoder().encode(times))
application = webapp.WSGIApplication(
[ (r'/routes/([\w-]+)/directions/([\w-]+)/stops/([\w-]+)/times', TimeController),
(r'/routes/([\w-]+)/directions/([\w-]+)/stops', StopsController),
(r'/routes/([\w-]+)/directions', DirectionsController),
(r'/routes', RoutesController) ],
debug=False)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()