shape up smsBEST parsing, add route grouping

This commit is contained in:
Schuyler Erle 2012-02-28 12:31:09 -08:00
parent b755c57e63
commit 9cf0a58c49

View File

@ -24,7 +24,8 @@ class App(AppBase):
msg.respond("Sorry, we found no route marked '%s'." % msg.text) msg.respond("Sorry, we found no route marked '%s'." % msg.text)
return return
origin, destination = stops[0]['properties'], stops[-1]['properties'] origin, destination = stops[0]['properties'], stops[-1]['properties']
msg.respond("%s: %s (%s) to %s (%s)" % (routes[0], msg.respond("%s: %s (%s) to %s (%s)" % (
",".join(routes),
origin['display_name'], origin['area'], origin['display_name'], origin['area'],
destination['display_name'], destination['area'])) destination['display_name'], destination['area']))
else: else:
@ -37,13 +38,10 @@ class App(AppBase):
stop = feature['properties'] stop = feature['properties']
area = PUNCT.sub('', stop['area']) area = PUNCT.sub('', stop['area'])
match = "%s (%s): %s" % (stop['official_name'], area, stop['routes']) match = "%s (%s): %s" % (stop['official_name'], area, stop['routes'])
if len(response) + len(match) + len(STYLE["repeat"]) < MAX_MSG_LEN: if len(response) > len(STYLE["repeat"]): response += STYLE["repeat"]
if len(response) > len(STYLE["repeat"]): response += STYLE["repeat"] response += match
response += match if len(response) > MAX_MSG_LEN: break
elif len(response) < len(STYLE["repeat"]): if len(response) > MAX_MSG_LEN:
response += match[:MAX_MSG_LEN-len(STYLE["start"])-len(STYLE["end"])+4] response = response[:MAX_MSG_LEN-(len(STYLE["end"])+4)] + "..."
response += " ..."
else:
break
response += STYLE["end"] response += STYLE["end"]
msg.respond(response) msg.respond(response)