From f43fdf5004cf4947a0e3d9bbf5932a010af97735 Mon Sep 17 00:00:00 2001 From: Schuyler Erle Date: Tue, 28 Feb 2012 12:56:10 -0800 Subject: [PATCH] Clean up repeated names in name queries. --- smsBEST/mumbai/app.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/smsBEST/mumbai/app.py b/smsBEST/mumbai/app.py index 95cc4f0..a7b067e 100644 --- a/smsBEST/mumbai/app.py +++ b/smsBEST/mumbai/app.py @@ -33,14 +33,20 @@ class App(AppBase): msg.respond("%s: %s (%s) to %s (%s)" % ( ",".join(routes), origin_name, origin_area, dest_name, dest_area)) else: - stops = ChaloBest.stops(q=msg.text)['features'] - if not stops: + features = ChaloBest.stops(q=msg.text)['features'] + if not features: msg.respond("Sorry, we found no stops like '%s'." % msg.text) return + stops = [] + for feat in features: + stop = feat['properties'] + if stops and stop["official_name"] == stops[-1]["official_name"]: + stops[-1]["routes"] += ", " + stop["routes"] + else: + stops.append(stop) response = STYLE["start"] - for feature in stops: - stop = feature['properties'] - match = "%s: %s" % (stop['official_name'], stop['routes']) + for stop in stops: + match = stop["official_name"] + ": " + stop["routes"] if len(response) > len(STYLE["repeat"]): response += STYLE["repeat"] response += match if len(response) > MAX_MSG_LEN: break