added bus route handler
This commit is contained in:
parent
88709f7bcf
commit
27c3f554ce
1
best/json/routes.json
Normal file
1
best/json/routes.json
Normal file
File diff suppressed because one or more lines are too long
29
best/smsmesn/handlers/route.py
Normal file
29
best/smsmesn/handlers/route.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
# 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")
|
||||
|
|
@ -26,7 +26,7 @@ class StopHandler(KeywordHandler):
|
|||
elif len(places) == 1:
|
||||
data = json.loads(open(join(JSON_PATH, "stopbus.json")).read().replace("\\", "/").replace(",,,", ",").replace(",,", ","))
|
||||
stop = getStop(data, places[0][1])
|
||||
stopStr = stop[1] + ": " + ",".join([val.split("|")[0] for val in stop[-1].split(",")])
|
||||
stopStr = str(stop[1]) + ": " + ",".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