added stop handler. freeze for now.
This commit is contained in:
parent
c6d23c1b76
commit
f42f4f3049
|
@ -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
|
||||
|
|
33
best/smsmesn/handlers/stop.py
Normal file
33
best/smsmesn/handlers/stop.py
Normal 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))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user