From 357600e1a8d8d55b82dc61d5a86942aa407ade3f Mon Sep 17 00:00:00 2001 From: Schuyler Erle Date: Tue, 28 Feb 2012 11:48:28 -0800 Subject: [PATCH] Fill up the response buffer on name queries. --- smsBEST/mumbai/app.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/smsBEST/mumbai/app.py b/smsBEST/mumbai/app.py index 1e566a0..5031670 100644 --- a/smsBEST/mumbai/app.py +++ b/smsBEST/mumbai/app.py @@ -2,6 +2,7 @@ from rapidsms.apps.base import AppBase import re import arrest +MAX_MSG_LEN = 160 DIGIT = re.compile(r"\d{1,3}") chalobest = arrest.Client("http://chalobest.in/1.0") @@ -16,6 +17,14 @@ class App(AppBase): 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'])) + stops = chalobest.stops(q=msg.text)['features'] + response = "" + for feature in stops: + stop = feature['properties'] + match = "%s (%s): %s" % (stop['official_name'], stop['area'], stop['routes']) + if len(response) + len(match) + 1 < MAX_MSG_LEN: + if response: response += ";" + response += match + else: + break + msg.respond(response)