From d04f61ab78b70d969f68f7fd49a4e51ba8af0ae8 Mon Sep 17 00:00:00 2001 From: Schuyler Erle Date: Tue, 28 Feb 2012 10:10:22 -0800 Subject: [PATCH] More or less working mumbai.app --- smsBEST/mumbai/app.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/smsBEST/mumbai/app.py b/smsBEST/mumbai/app.py index e87ddb0..1e566a0 100644 --- a/smsBEST/mumbai/app.py +++ b/smsBEST/mumbai/app.py @@ -1,4 +1,21 @@ from rapidsms.apps.base import AppBase +import re +import arrest + +DIGIT = re.compile(r"\d{1,3}") +chalobest = arrest.Client("http://chalobest.in/1.0") class App(AppBase): - pass + def handle(self, msg): + if DIGIT.search(msg.text): + routes = chalobest.routes(q=msg.text.replace(" ", "")) + detail = chalobest.route[routes[0]] + stops = detail['stops']['features'] + origin, destination = stops[0]['properties'], stops[-1]['properties'] + msg.respond("%s: %s (%s) to %s (%s)" % (routes[0], + origin['display_name'], origin['area'], + destination['display_name'], destination['area'])) + else: + stops = chalobest.stops(q=msg.text) + stop = stops['features'][0]['properties'] + msg.respond("%s (%s): %s" % (stop['official_name'], stop['area'], stop['routes']))