Fill up the response buffer on name queries.

This commit is contained in:
Schuyler Erle 2012-02-28 11:48:28 -08:00
parent d04f61ab78
commit 357600e1a8

View File

@ -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)