fixed some crashes in tfl.py.
This commit is contained in:
parent
36e12dda1f
commit
07457a3626
1 changed files with 10 additions and 9 deletions
|
@ -59,8 +59,10 @@ class Module(object):
|
||||||
for bus in bus_stop:
|
for bus in bus_stop:
|
||||||
bus_number = bus["lineName"]
|
bus_number = bus["lineName"]
|
||||||
bus_due_iso8601 = bus["expectedArrival"]
|
bus_due_iso8601 = bus["expectedArrival"]
|
||||||
bus_due = datetime.datetime.strptime(bus_due_iso8601.split(".")[0],
|
if "." in bus_due_iso8601:
|
||||||
"%Y-%m-%dT%H:%M:%S")
|
bus_due_iso8601 = bus_due_iso8601.split(".")[0]+"Z"
|
||||||
|
bus_due = datetime.datetime.strptime(bus_due_iso8601,
|
||||||
|
"%Y-%m-%dT%H:%M:%SZ")
|
||||||
time_until = bus_due-datetime.datetime.utcnow()
|
time_until = bus_due-datetime.datetime.utcnow()
|
||||||
time_until = int(time_until.total_seconds()/60)
|
time_until = int(time_until.total_seconds()/60)
|
||||||
busses.append([bus_number, time_until])
|
busses.append([bus_number, time_until])
|
||||||
|
@ -130,12 +132,11 @@ class Module(object):
|
||||||
app_id = self.bot.config["tfl-api-id"]
|
app_id = self.bot.config["tfl-api-id"]
|
||||||
app_key = self.bot.config["tfl-api-key"]
|
app_key = self.bot.config["tfl-api-key"]
|
||||||
stop_name = event["args"]
|
stop_name = event["args"]
|
||||||
print(URL_STOP_SEARCH % stop_name)
|
|
||||||
stop_search = Utils.get_url(URL_STOP_SEARCH % stop_name, get_params={
|
stop_search = Utils.get_url(URL_STOP_SEARCH % stop_name, get_params={
|
||||||
"app_id": app_id, "app_key": app_key, "maxResults": "4", "faresOnly": "False"}, json=True)
|
"app_id": app_id, "app_key": app_key, "maxResults": "4", "faresOnly": "False"}, json=True)
|
||||||
print(stop_search)
|
if stop_search:
|
||||||
for stop in stop_search["matches"]:
|
for stop in stop_search["matches"]:
|
||||||
print(stop)
|
print(stop)
|
||||||
|
|
||||||
results = ["%s (%s): %s" % (stop["name"], ", ".join(stop["modes"]), stop["id"]) for stop in stop_search["matches"]]
|
results = ["%s (%s): %s" % (stop["name"], ", ".join(stop["modes"]), stop["id"]) for stop in stop_search["matches"]]
|
||||||
event["stdout"].write("; ".join(results))
|
event["stdout"].write("; ".join(results))
|
||||||
|
event["stderr"].write("Stop not found")
|
||||||
|
|
Loading…
Reference in a new issue