--- a/schedule_viewer.py +++ b/schedule_viewer.py @@ -282,6 +282,23 @@ result.sort(key = lambda x: x[1:3]) return result + def handle_json_GET_routesearch(self, params): + """Return a list of routes with matching short name.""" + schedule = self.server.schedule + routeshortname = params.get('routeshortname', None) + result = [] + for r in schedule.GetRouteList(): + if r.route_short_name == routeshortname: + servicep = None + for t in schedule.GetTripList(): + if t.route_id == r.route_id: + servicep = t.service_period + break + result.append( (r.route_id, r.route_short_name, r.route_long_name, servicep.service_id) ) + result.sort(key = lambda x: x[1:3]) + return result + + def handle_json_GET_routerow(self, params): schedule = self.server.schedule route = schedule.GetRoute(params.get('route', None)) @@ -361,7 +378,7 @@ schedule = self.server.schedule lat = float(params.get('lat')) lon = float(params.get('lon')) - limit = int(params.get('limit')) + limit = int(params.get('limit',5)) scale = int(params.get('scale',5)) # 5 = neighbourhood ~ 1km, 4= town 5 by 7km stops = [] @@ -385,6 +402,7 @@ stops.append(s) if scale == 5: + print stops return [StopToTuple(s) for s in stops] else: dist_stop_list = [] @@ -396,7 +414,8 @@ elif dist < dist_stop_list[-1][0]: bisect.insort(dist_stop_list, (dist, s)) dist_stop_list.pop() # Remove stop with greatest distance - return [StopToTuple(s) for s in dist_stop_list] + print dist_stop_list + return [StopToTuple(s) for dist, s in dist_stop_list] def handle_json_GET_boundboxstops(self, params): """Return a list of up to 'limit' stops within bounding box with 'n','e' @@ -475,8 +494,8 @@ result = {} for trip in trips: route = schedule.GetRoute(trip.route_id) - if not trip.route_short_name+route.route_long_name in result: - result[trip.route_short_name+route.route_long_name] = (route.route_id, route.route_short_name, route.route_long_name, trip.trip_id) + if not route.route_short_name+route.route_long_name+trip.service_id in result: + result[route.route_short_name+route.route_long_name+trip.service_id] = (route.route_id, route.route_short_name, route.route_long_name, trip.trip_id, trip.service_id) return result def handle_json_GET_stopalltrips(self, params): @@ -507,6 +526,8 @@ if service_period == None or trip.service_id == service_period: result.append((time, (trip.trip_id, trip_name, trip.service_id), tp)) return result + + def handle_json_GET_stoptrips(self, params): """Given a stop_id and time in seconds since midnight return the next @@ -516,7 +537,7 @@ requested_time = int(params.get('time', 0)) limit = int(params.get('limit', 15)) service_period = params.get('service_period', None) - time_range = params.get('time_range', 24*60*60) + time_range = int(params.get('time_range', 24*60*60)) filtered_time_trips = []