return stopnames with query

This commit is contained in:
Sanj 2011-08-06 19:53:50 +05:30
parent 067e344f75
commit 413c1ca49e
2 changed files with 6 additions and 3 deletions

View File

@ -53,12 +53,13 @@ def getBuses(frm, to):
toArr = stopListTo.split(",") toArr = stopListTo.split(",")
toArr = [val.split("|")[0] for val in toArr] toArr = [val.split("|")[0] for val in toArr]
intersectArr = [val for val in fromArr if val in toArr] intersectArr = [val for val in fromArr if val in toArr]
fromToStr = "from " + frm[1] + " to " + to[1] + ": "
# return ",".join(fromArr) + ",".join(toArr) # return ",".join(fromArr) + ",".join(toArr)
if (len(intersectArr) == 0): if (len(intersectArr) == 0):
return "no direct buses found." return fromToStr + "no direct buses found."
# return "from %s to %s" % (",".join(fromArr), ",".join(toArr),) # return "from %s to %s" % (",".join(fromArr), ",".join(toArr),)
else: else:
return ",".join(intersectArr) return fromToStr + ",".join(intersectArr)
class FromToHandler(KeywordHandler): class FromToHandler(KeywordHandler):
keyword = "from" keyword = "from"
@ -93,6 +94,7 @@ class FromToHandler(KeywordHandler):
toString = "to %s" % (tos[0][1]) toString = "to %s" % (tos[0][1])
else: else:
toString = "to %s" % (getOptions(tos)) toString = "to %s" % (getOptions(tos))
toString = "To location not found."
self.respond(fromString + " " + toString) self.respond(fromString + " " + toString)

View File

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