diff options
| author | 2016-07-13 07:05:46 +0100 | |
|---|---|---|
| committer | 2016-07-13 07:05:46 +0100 | |
| commit | 07457a362695b5ab3bdf095295b79a94695f2d5a (patch) | |
| tree | 3267321f505e85709ca0b292480473c11497a01e /modules/tfl.py | |
| parent | TfL stop search, 'bus' can now accept proper IDs, fixed issue with time in ms (diff) | |
fixed some crashes in tfl.py.
Diffstat (limited to 'modules/tfl.py')
| -rw-r--r-- | modules/tfl.py | 19 |
1 files 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") |
