From f5386cf233cc86a7accdd58856c96fc9cb3b77c3 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 6 Sep 2012 19:06:06 +0530 Subject: [PATCH] Combine routes of stops with the same name --- smsBEST/mumbai/app.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/smsBEST/mumbai/app.py b/smsBEST/mumbai/app.py index 25bd951..d1ebf78 100644 --- a/smsBEST/mumbai/app.py +++ b/smsBEST/mumbai/app.py @@ -18,6 +18,18 @@ STYLE = {"start": "", "repeat": "; ", "end": ""} ChaloBest = arrest.Client("http://chalobest.in/1.0") +def get_routes_for_matches(stops): + same_stops = [] + same_stops.append(stops[0]) + if len(stops) > 1: + for s in stops[1:]: + if s['properties']['official_name'] == stops[0]['properties']['official_name']: + same_stops.append(s) + routes = [] + for stop in same_stops: + routes.append(stop['properties']['routes'].split(", ")) + return routes + class App(AppBase): def handle(self, msg): if DIGIT.search(msg.text): @@ -40,12 +52,12 @@ class App(AppBase): msg.respond("Sorry, found no stop matching '%s'" % stop1txt) return best_match1 = stop1matches[0] - routes1 = best_match1['properties']['routes'] + routes1 = get_routes_for_matches(stop1matches) stop2matches = ChaloBest.stops(q=stop2txt)['features'] if not stop2matches: msg.respond("Sorry, found no stop matching '%s'" % stop2txt) best_match2 = stop2matches[0] - routes2 = best_match2['properties']['routes'] + routes2 = get_routes_for_matches(stop2matches) routes1arr = set(routes1.split(", ")) routes2arr = set(routes2.split(", ")) intersection = list(routes1arr.intersection(routes2arr))