bestSMS/best/new_best/handlers/bus.py.old
2011-07-16 11:41:20 +05:30

38 lines
1.1 KiB
Python

#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4
from rapidsms.contrib.handlers.handlers.keyword import KeywordHandler
from buses.models import *
class BestHandler(KeywordHandler):
keyword = "routeold"
def help(self):
self.respond("Send route <bus_no>")
def handle(self, text):
bus_no = text.strip()
a = Atlas.objects.filter(route__iexact=bus_no)
if len(a) < 1:
self.respond("Did not find that bus number. Sorry.")
else:
a = a[0]
src = a.src
first_src = time_str(a.first_src)
last_src = time_str(a.last_src)
dest = a.dest
first_dest = time_str(a.first_dest)
last_dest = time_str(a.last_dest)
schedule = a.schedule
ret = "%s(%s-%s) to %s(%s-%s) from %s" % (src, str(first_src), str(last_src), dest, str(first_dest), str(last_dest), schedule)
self.respond(ret)
def time_str(no):
whole = int(no)
decimal = (no - whole) * 10
mins = int(((decimal + .0) / 10) * 60)
return str(whole) + ":" + str(mins)