--- a/busui/schedule_viewer.py +++ b/busui/schedule_viewer.py @@ -88,7 +88,10 @@ def StopToTuple(stop): """Return tuple as expected by javascript function addStopMarkerFromList""" return (stop.stop_id, stop.stop_name, float(stop.stop_lat), - float(stop.stop_lon), stop.location_type) + float(stop.stop_lon), stop.location_type, stop.stop_code) +def StopCodeToTuple(stop, code): + return (stop.stop_id, stop.stop_name, float(stop.stop_lat), + float(stop.stop_lon), stop.location_type, code) class ScheduleRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): @@ -301,11 +304,11 @@ except KeyError: # if a non-existent trip is searched for, the return nothing return - time_stops = trip.GetTimeStops() + time_stops = trip.GetTimeInterpolatedStops() stops = [] times = [] - for arr,dep,stop in time_stops: - stops.append(StopToTuple(stop)) + for arr,ts,is_timingpoint in time_stops: + stops.append(StopToTuple(ts.stop)) times.append(arr) return [stops, times] @@ -357,8 +360,10 @@ schedule = self.server.schedule matches = [] for s in schedule.GetStopList(): + #wtf, stop_code changes into stop_name after .find() + virginstopCode = s.stop_code if s.stop_code.find("Wj") == -1: - matches.append(StopToTuple(s)) + matches.append(StopCodeToTuple(s,virginstopCode)) return matches def handle_json_GET_stopsearch(self, params): @@ -366,8 +371,28 @@ query = params.get('q', None).lower() matches = [] for s in schedule.GetStopList(): - if s.stop_id.lower().find(query) != -1 or s.stop_name.lower().find(query) != -1: + if s.stop_name.lower().find(query) != -1 or s.stop_code.lower().find(query) != -1: matches.append(StopToTuple(s)) + return matches + + def handle_json_GET_stopnamesearch(self, params): + schedule = self.server.schedule + query = params.get('q', None).lower() + matches = [] + for s in schedule.GetStopList(): + if s.stop_name.lower().find(query) != -1: + matches.append(StopToTuple(s)) + return matches + + def handle_json_GET_stopcodesearch(self, params): + schedule = self.server.schedule + query = params.get('q', None).lower() + matches = [] + for s in schedule.GetStopList(): + #wtf, stop_code changes into stop_name after .find() + virginstopCode = s.stop_code + if s.stop_code.lower().find(query) != -1: + matches.append(StopCodeToTuple(s,virginstopCode)) return matches def handle_json_GET_stop(self, params):