bestSMS/best/smsmesn/handlers/route.py
2011-10-15 14:04:38 -04:00

30 lines
847 B
Python
Executable File

# from fromto import getStop, getStops, getOptions
from rapidsms.contrib.handlers.handlers.keyword import KeywordHandler
# from new_best.models import *
import datetime
try:
import json
except:
import simplejson as json
from settings import JSON_PATH
from os.path import join
class BusHandler(KeywordHandler):
keyword = "bus"
def help(self):
self.respond("Send bus <bus_no> to get first and last stop.")
def handle(self, text):
bus_no = text.strip().lower()
busList = json.loads(open(join(JSON_PATH, "routes.json")).read())
found = False
for b in busList:
if b[0].strip() == bus_no or b[1].strip() == bus_no:
self.respond("from " + b[2] + " to " + b[3])
found = True
if not found:
self.respond("sorry, bus not found")