added stop handler. freeze for now.

This commit is contained in:
Sanj 2011-07-23 18:02:24 +05:30
parent c6d23c1b76
commit f42f4f3049
2 changed files with 35 additions and 0 deletions

View File

@ -95,6 +95,8 @@ class FromToHandler(KeywordHandler):
toString = "to %s" % (getOptions(tos))
self.respond(fromString + " " + toString)
def time_str(no):
whole = int(no)
decimal = (no - whole) * 10

View File

@ -0,0 +1,33 @@
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 StopHandler(KeywordHandler):
keyword = "stop"
def help(self):
self.respond("Send stop <stop_name> to get buses that stop at a particular stop.")
def handle(self, text):
place = text.strip().lower()
stopList = json.loads(open(join(JSON_PATH, "stoplist.json")).read().replace("\\", "/"))
places = getStops(stopList, place)
if len(places) == 0:
self.respond("place not found.")
elif len(places) == 1:
data = json.loads(open(join(JSON_PATH, "stopbus.json")).read().replace("\\", "/").replace(",,,", ",").replace(",,", ","))
stop = getStop(data, places[0][1])
stopStr = ",".join([val.split("|")[0] for val in stop[-1].split(",")])
self.respond(stopStr)
else:
self.respond("try one of: %s" % getOptions(places))