bestSMS/best/new_best/handlers/bus.py
2011-10-15 14:04:38 -04:00

34 lines
837 B
Python
Executable File

#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4
from rapidsms.contrib.handlers.handlers.keyword import KeywordHandler
from new_best.models import *
import datetime
try:
import json
except:
import simplejson as json
class BestHandler(KeywordHandler):
keyword = "route"
def help(self):
self.respond("Send route <bus_no>")
def handle(self, text):
bus_no = text.strip()
now = datetime.datetime.now()
try:
a = Atlas.get_atlas(bus_no, now)
self.respond("route %s from %s to %s" % (a['route'],a['from'], a['to']))
except:
self.respond("Did not find bus number %s. Sorry." % bus_no)
def time_str(no):
whole = int(no)
decimal = (no - whole) * 10
mins = int(((decimal + .0) / 10) * 60)
return str(whole) + ":" + str(mins)