From 07457a362695b5ab3bdf095295b79a94695f2d5a Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 13 Jul 2016 07:05:46 +0100 Subject: [PATCH] fixed some crashes in tfl.py. --- modules/tfl.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/tfl.py b/modules/tfl.py index 88c70587..074503d7 100644 --- a/modules/tfl.py +++ b/modules/tfl.py @@ -59,8 +59,10 @@ class Module(object): for bus in bus_stop: bus_number = bus["lineName"] bus_due_iso8601 = bus["expectedArrival"] - bus_due = datetime.datetime.strptime(bus_due_iso8601.split(".")[0], - "%Y-%m-%dT%H:%M:%S") + if "." in bus_due_iso8601: + 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 = int(time_until.total_seconds()/60) busses.append([bus_number, time_until]) @@ -130,12 +132,11 @@ class Module(object): app_id = self.bot.config["tfl-api-id"] app_key = self.bot.config["tfl-api-key"] stop_name = event["args"] - print(URL_STOP_SEARCH % stop_name) 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) - print(stop_search) - for stop in stop_search["matches"]: - print(stop) - - results = ["%s (%s): %s" % (stop["name"], ", ".join(stop["modes"]), stop["id"]) for stop in stop_search["matches"]] - event["stdout"].write("; ".join(results)) + if stop_search: + for stop in stop_search["matches"]: + print(stop) + results = ["%s (%s): %s" % (stop["name"], ", ".join(stop["modes"]), stop["id"]) for stop in stop_search["matches"]] + event["stdout"].write("; ".join(results)) + event["stderr"].write("Stop not found")