switch to using pytz instead of an API for localised time
This commit is contained in:
parent
1e79ed4249
commit
638df8729e
2 changed files with 6 additions and 17 deletions
|
@ -2,9 +2,9 @@
|
||||||
#--depends-on location
|
#--depends-on location
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import pytz
|
||||||
from src import ModuleManager, utils
|
from src import ModuleManager, utils
|
||||||
|
|
||||||
API = "http://worldtimeapi.org/api/timezone/%s"
|
|
||||||
NOLOCATION = "%s doesn't have a location set"
|
NOLOCATION = "%s doesn't have a location set"
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
|
@ -26,22 +26,10 @@ class Module(ModuleManager.BaseModule):
|
||||||
def time(self, event):
|
def time(self, event):
|
||||||
target_user, location = self._find_setting(event)
|
target_user, location = self._find_setting(event)
|
||||||
if not location == None:
|
if not location == None:
|
||||||
page = utils.http.request(API % location["timezone"], json=True)
|
dt = datetime.datetime.now(tz=pytz.timezone(location["timezone"]))
|
||||||
|
human = utils.datetime_human(dt)
|
||||||
if page and page.data and not page.data.get("error", None):
|
event["stdout"].write("Time for %s: %s" % (target_user.nickname,
|
||||||
iso8601 = page.data["datetime"]
|
human))
|
||||||
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()
|
|
||||||
else:
|
else:
|
||||||
event["stderr"].write(NOLOCATION % target_user.nickname)
|
event["stderr"].write(NOLOCATION % target_user.nickname)
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ feedparser
|
||||||
lxml
|
lxml
|
||||||
netifaces
|
netifaces
|
||||||
PySocks
|
PySocks
|
||||||
|
pytz
|
||||||
requests
|
requests
|
||||||
scrypt
|
scrypt
|
||||||
suds-jurko
|
suds-jurko
|
||||||
|
|
Loading…
Reference in a new issue