From 4cd706c9286c3d304d2807006135040367c1d701 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 30 Aug 2012 19:05:33 +0530 Subject: [PATCH 01/13] links to R / UNR --- chaloBEST/templates/fuzzystops.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/chaloBEST/templates/fuzzystops.html b/chaloBEST/templates/fuzzystops.html index 8967855..e0a45c7 100644 --- a/chaloBEST/templates/fuzzystops.html +++ b/chaloBEST/templates/fuzzystops.html @@ -106,6 +106,7 @@ function saveUNR(elem, markChecked) { To Txt To Stop + @@ -141,6 +142,11 @@ function saveUNR(elem, markChecked) {   + + R   + UNR   + + {% endfor %} From 6538b1a1de0992c162ab1028488f7256a55c3d99 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 30 Aug 2012 20:09:01 +0530 Subject: [PATCH 02/13] add link to route page --- chaloBEST/templates/fuzzystops.html | 1 + 1 file changed, 1 insertion(+) diff --git a/chaloBEST/templates/fuzzystops.html b/chaloBEST/templates/fuzzystops.html index e0a45c7..ec4c667 100644 --- a/chaloBEST/templates/fuzzystops.html +++ b/chaloBEST/templates/fuzzystops.html @@ -145,6 +145,7 @@ function saveUNR(elem, markChecked) { R   UNR   + Map From f517b9ef36b11b4385eeeb0202520aa2387fa610 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sat, 1 Sep 2012 17:13:16 +0530 Subject: [PATCH 03/13] fix smsbest settings for django upgrade --- smsBEST/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smsBEST/settings.py b/smsBEST/settings.py index b6c3d8a..a4476a7 100644 --- a/smsBEST/settings.py +++ b/smsBEST/settings.py @@ -150,7 +150,7 @@ LOG_BACKUPS = 256 # number of logs to keep # these weird dependencies should be handled by their respective apps, # but they're not, so here they are. most of them are for django admin. TEMPLATE_CONTEXT_PROCESSORS = [ - "django.core.context_processors.auth", + "django.contrib.auth.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", From 6299992b402e08d84e6e0404a547ef508a81ae71 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 7 Jan 2008 08:42:49 +0530 Subject: [PATCH 04/13] remove facebook-sdk from requirements --- requirements.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 1e718e8..c643d6d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ PIL==1.1.7 RapidSMS==0.9.6a South==0.7.5 -e git://github.com/schuyler/arrest.git@0017837a45bcb31786f953fba976d454ae684ecc#egg=arrest-dev +-e git://github.com/etianen/django-reversion.git#egg=reversion chardet==1.0.1 django-allauth==0.5.0 django-avatar==1.0.5 @@ -19,9 +20,12 @@ django-socialregistration==0.5.4 django-userena==1.1.2 djappsettings==0.1.0 djtables==0.1.2 + +#facebook-python-sdk==0.1 +#-e git://github.com/jhaddad/facebook-python-sdk#egg=facebook-python-sdk + easy-thumbnails==1.0.3 -facebook-python-sdk==0.1 -facebook-sdk==0.3.1 +#facebook-sdk==0.3.1 feedparser==5.1.2 -e git://github.com/seatgeek/fuzzywuzzy.git@c73e3d32e3bb4d31dc38cc64e3a3362855d4d249#egg=fuzzywuzzy-dev httplib2==0.7.4 From 92791cc2b954db633800a1097d0f3f4f85b4b931 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 6 Sep 2012 16:00:34 +0530 Subject: [PATCH 05/13] silly typo --- chaloBEST/templates/fuzzystops.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaloBEST/templates/fuzzystops.html b/chaloBEST/templates/fuzzystops.html index ec4c667..b4dbe0a 100644 --- a/chaloBEST/templates/fuzzystops.html +++ b/chaloBEST/templates/fuzzystops.html @@ -145,7 +145,7 @@ function saveUNR(elem, markChecked) { R   UNR   - Map + Map From d2f401a8e0bcaa1b9e83250cf65a593d1eb63df7 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 6 Sep 2012 18:23:08 +0530 Subject: [PATCH 06/13] Add syntax for "to" queries --- smsBEST/mumbai/app.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/smsBEST/mumbai/app.py b/smsBEST/mumbai/app.py index 8c693b9..25bd951 100644 --- a/smsBEST/mumbai/app.py +++ b/smsBEST/mumbai/app.py @@ -32,6 +32,31 @@ class App(AppBase): origin_area, dest_area = PUNCT.sub('', origin['area']), PUNCT.sub('', dest['area']) msg.respond("%s: %s (%s) to %s (%s)" % ( ",".join(routes), origin_name, origin_area, dest_name, dest_area)) + elif msg.text.find(" to ") != -1: + stop1txt = msg.text.split("to")[0].strip() + stop2txt = msg.text.split("to")[1].strip() + stop1matches = ChaloBest.stops(q=stop1txt)['features'] + if not stop1matches: + msg.respond("Sorry, found no stop matching '%s'" % stop1txt) + return + best_match1 = stop1matches[0] + routes1 = best_match1['properties']['routes'] + 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'] + routes1arr = set(routes1.split(", ")) + routes2arr = set(routes2.split(", ")) + intersection = list(routes1arr.intersection(routes2arr)) + if len(intersection) == 0: + msg.respond("Sorry, no direct buses found between %s and %s" % (best_match1['properties']['official_name'], best_match2['properties']['official_name'],)) + return + routesFound = ", ".join(intersection) + msg.respond("Routes between %s and %s: %s" % (best_match1['properties']['official_name'], best_match2['properties']['official_name'], routesFound,)) + return + + else: features = ChaloBest.stops(q=msg.text)['features'] if not features: From f5386cf233cc86a7accdd58856c96fc9cb3b77c3 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 6 Sep 2012 19:06:06 +0530 Subject: [PATCH 07/13] 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)) From 92dd5b2a91ba4f1b8d621a2f37cb9fc79dd5059a Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 6 Sep 2012 19:14:02 +0530 Subject: [PATCH 08/13] silly --- smsBEST/mumbai/app.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/smsBEST/mumbai/app.py b/smsBEST/mumbai/app.py index d1ebf78..824f0b1 100644 --- a/smsBEST/mumbai/app.py +++ b/smsBEST/mumbai/app.py @@ -52,15 +52,15 @@ class App(AppBase): msg.respond("Sorry, found no stop matching '%s'" % stop1txt) return best_match1 = stop1matches[0] - routes1 = get_routes_for_matches(stop1matches) + routes1 = set(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 = get_routes_for_matches(stop2matches) - routes1arr = set(routes1.split(", ")) - routes2arr = set(routes2.split(", ")) - intersection = list(routes1arr.intersection(routes2arr)) + routes2 = set(get_routes_for_matches(stop2matches)) + #routes1arr = set(routes1.split(", ")) + #routes2arr = set(routes2.split(", ")) + intersection = list(routes1.intersection(routes2)) if len(intersection) == 0: msg.respond("Sorry, no direct buses found between %s and %s" % (best_match1['properties']['official_name'], best_match2['properties']['official_name'],)) return From 11fb39da4a47ef6b031510fa41ec39faf45af4d7 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 6 Sep 2012 19:19:08 +0530 Subject: [PATCH 09/13] extend not append --- smsBEST/mumbai/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smsBEST/mumbai/app.py b/smsBEST/mumbai/app.py index 824f0b1..6d1a9a3 100644 --- a/smsBEST/mumbai/app.py +++ b/smsBEST/mumbai/app.py @@ -27,7 +27,7 @@ def get_routes_for_matches(stops): same_stops.append(s) routes = [] for stop in same_stops: - routes.append(stop['properties']['routes'].split(", ")) + routes.extend(stop['properties']['routes'].split(", ")) return routes class App(AppBase): From 7b5d3df2dbd31bae456cc83cebf51155a21453bc Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 6 Sep 2012 19:21:06 +0530 Subject: [PATCH 10/13] string change --- smsBEST/mumbai/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smsBEST/mumbai/app.py b/smsBEST/mumbai/app.py index 6d1a9a3..a6f54f8 100644 --- a/smsBEST/mumbai/app.py +++ b/smsBEST/mumbai/app.py @@ -65,7 +65,7 @@ class App(AppBase): msg.respond("Sorry, no direct buses found between %s and %s" % (best_match1['properties']['official_name'], best_match2['properties']['official_name'],)) return routesFound = ", ".join(intersection) - msg.respond("Routes between %s and %s: %s" % (best_match1['properties']['official_name'], best_match2['properties']['official_name'], routesFound,)) + msg.respond("%s to %s: %s" % (best_match1['properties']['official_name'], best_match2['properties']['official_name'], routesFound,)) return From d9d2dacd853baf721f0f6f439c215e196c2a4052 Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 11 Sep 2012 16:28:35 +0530 Subject: [PATCH 11/13] add rudimentary area queries --- smsBEST/mumbai/app.py | 81 ++++++++++++++++++++++++++++++++----------- 1 file changed, 60 insertions(+), 21 deletions(-) diff --git a/smsBEST/mumbai/app.py b/smsBEST/mumbai/app.py index a6f54f8..99ffeb7 100644 --- a/smsBEST/mumbai/app.py +++ b/smsBEST/mumbai/app.py @@ -19,17 +19,45 @@ 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) +# 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: + for stop in stops: routes.extend(stop['properties']['routes'].split(", ")) return routes +def get_stops_for_string(s): + stops = [] + s = s.strip() + areas = ChaloBest.areas(q=s) + if len(areas) > 0: + for a in areas: + area = ChaloBest.area[a] + for stop in area['stops']['features']: + stops.append(stop) + return { + 'name': ", ".join(areas), + 'stops': stops + } + else: + stops_results = ChaloBest.stops(q=s) + if len(stops_results) == 0: + return None + same_stops = [] + same_stops.append(stops[0]) + if len(stops_results) > 1: + for s in stops_results[1:]: + if s['properties']['official_name'] == stops[0]['properties']['official_name']: + same_stops.append(s) + return { + 'name': stops[0]['properties']['display_name'], + 'stops': same_stops + } + class App(AppBase): def handle(self, msg): if DIGIT.search(msg.text): @@ -37,6 +65,12 @@ class App(AppBase): if not routes: msg.respond("Sorry, we found no route marked '%(text)s'.", text=msg.text) return + detail = None + for route in routes: + if route.replace(" ", "").upper() == msg.text.replace(" ", "").upper(): + detail = ChaloBest.route[route] + if detail == None: + detail = ChaloBest.route[routes[0]] detail = ChaloBest.route[routes[0]] stops = detail['stops']['features'] origin, dest = stops[0]['properties'], stops[-1]['properties'] @@ -45,27 +79,32 @@ class App(AppBase): msg.respond("%s: %s (%s) to %s (%s)" % ( ",".join(routes), origin_name, origin_area, dest_name, dest_area)) elif msg.text.find(" to ") != -1: - stop1txt = msg.text.split("to")[0].strip() - stop2txt = msg.text.split("to")[1].strip() - stop1matches = ChaloBest.stops(q=stop1txt)['features'] - if not stop1matches: - msg.respond("Sorry, found no stop matching '%s'" % stop1txt) + + from_txt = msg.text.split("to")[0].strip() + to_txt = msg.text.split("to")[1].strip() + + from_matches = get_stops_for_string(from_txt) + to_matches = get_stops_for_string(to_txt) + +# stop1matches = ChaloBest.stops(q=stop1txt)['features'] + if not from_matches: + msg.respond("Sorry, found no stop matching '%s'" % from_txt) return - best_match1 = stop1matches[0] - routes1 = set(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 = set(get_routes_for_matches(stop2matches)) + #best_match1 = stop1matches[0] + routes1 = set(get_routes_for_matches(from_matches['stops'])) + #stop2matches = ChaloBest.stops(q=stop2txt)['features'] + if not to_matches: + msg.respond("Sorry, found no stop matching '%s'" % to_txt) + #best_match2 = stop2matches[0] + routes2 = set(get_routes_for_matches(to_matches['stops'])) #routes1arr = set(routes1.split(", ")) #routes2arr = set(routes2.split(", ")) intersection = list(routes1.intersection(routes2)) if len(intersection) == 0: - msg.respond("Sorry, no direct buses found between %s and %s" % (best_match1['properties']['official_name'], best_match2['properties']['official_name'],)) + msg.respond("Sorry, no direct buses found between %s and %s" % (from_matches['name'], to_matches['name'],)) return routesFound = ", ".join(intersection) - msg.respond("%s to %s: %s" % (best_match1['properties']['official_name'], best_match2['properties']['official_name'], routesFound,)) + msg.respond("%s to %s: %s" % (from_matches['name'], to_matches['name'], routesFound,)) return From aaabf82ee5c772d64a029f4ec2e3cb58d0bdce1f Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 11 Sep 2012 16:37:14 +0530 Subject: [PATCH 12/13] silly --- smsBEST/mumbai/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smsBEST/mumbai/app.py b/smsBEST/mumbai/app.py index 99ffeb7..429f1a7 100644 --- a/smsBEST/mumbai/app.py +++ b/smsBEST/mumbai/app.py @@ -44,7 +44,7 @@ def get_stops_for_string(s): 'stops': stops } else: - stops_results = ChaloBest.stops(q=s) + stops_results = ChaloBest.stops(q=s)['features'] if len(stops_results) == 0: return None same_stops = [] From 16696ec09c114b477128aa56c1be8c7f75487328 Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 11 Sep 2012 16:43:22 +0530 Subject: [PATCH 13/13] fix errors for stop lookups --- smsBEST/mumbai/app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/smsBEST/mumbai/app.py b/smsBEST/mumbai/app.py index 429f1a7..6745084 100644 --- a/smsBEST/mumbai/app.py +++ b/smsBEST/mumbai/app.py @@ -48,13 +48,13 @@ def get_stops_for_string(s): if len(stops_results) == 0: return None same_stops = [] - same_stops.append(stops[0]) + same_stops.append(stops_results[0]) if len(stops_results) > 1: for s in stops_results[1:]: - if s['properties']['official_name'] == stops[0]['properties']['official_name']: + if s['properties']['official_name'] == same_stops[0]['properties']['official_name']: same_stops.append(s) return { - 'name': stops[0]['properties']['display_name'], + 'name': same_stops[0]['properties']['display_name'], 'stops': same_stops }