2012-02-28 16:59:30 +00:00
|
|
|
from rapidsms.apps.base import AppBase
|
2012-02-28 18:10:22 +00:00
|
|
|
import re
|
|
|
|
import arrest
|
|
|
|
|
|
|
|
DIGIT = re.compile(r"\d{1,3}")
|
|
|
|
chalobest = arrest.Client("http://chalobest.in/1.0")
|
2012-02-28 16:59:30 +00:00
|
|
|
|
|
|
|
class App(AppBase):
|
2012-02-28 18:10:22 +00:00
|
|
|
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']))
|