From 638df8729e870366d5386afe090866b2faf54038 Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 5 Sep 2019 12:25:17 +0100 Subject: [PATCH] switch to using pytz instead of an API for localised time --- modules/user_time.py | 22 +++++----------------- requirements.txt | 1 + 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/modules/user_time.py b/modules/user_time.py index 8fe3faa2..fd8c42d7 100644 --- a/modules/user_time.py +++ b/modules/user_time.py @@ -2,9 +2,9 @@ #--depends-on location import datetime +import pytz from src import ModuleManager, utils -API = "http://worldtimeapi.org/api/timezone/%s" NOLOCATION = "%s doesn't have a location set" class Module(ModuleManager.BaseModule): @@ -26,22 +26,10 @@ class Module(ModuleManager.BaseModule): def time(self, event): target_user, location = self._find_setting(event) if not location == None: - page = utils.http.request(API % location["timezone"], json=True) - - if page and page.data and not page.data.get("error", None): - iso8601 = page.data["datetime"] - iso8601_dt, sep, timezone = iso8601.partition("+") - if sep: - iso8601 = "%s+%s" % ( - iso8601_dt, timezone.replace(":", "", 1)) - - dt = utils.iso8601_parse(page.data["datetime"], - microseconds=True) - human = utils.datetime_human(dt) - event["stdout"].write("Time for %s: %s" % (target_user.nickname, - human)) - else: - raise utils.EventsResultsError() + dt = datetime.datetime.now(tz=pytz.timezone(location["timezone"])) + human = utils.datetime_human(dt) + event["stdout"].write("Time for %s: %s" % (target_user.nickname, + human)) else: event["stderr"].write(NOLOCATION % target_user.nickname) diff --git a/requirements.txt b/requirements.txt index 84588df6..d48c280f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,7 @@ feedparser lxml netifaces PySocks +pytz requests scrypt suds-jurko