[modules/datetimetz] Add logging
This commit is contained in:
parent
3d6448cca6
commit
59ad411b2f
1 changed files with 10 additions and 3 deletions
|
@ -17,6 +17,7 @@ Parameters:
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
import datetime
|
import datetime
|
||||||
import locale
|
import locale
|
||||||
|
import logging
|
||||||
try:
|
try:
|
||||||
import pytz
|
import pytz
|
||||||
import tzlocal
|
import tzlocal
|
||||||
|
@ -41,10 +42,15 @@ class Module(bumblebee.engine.Module):
|
||||||
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, cmd=self.next_tz)
|
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, cmd=self.next_tz)
|
||||||
engine.input.register_callback(self, button=bumblebee.input.RIGHT_MOUSE, cmd=self.prev_tz)
|
engine.input.register_callback(self, button=bumblebee.input.RIGHT_MOUSE, cmd=self.prev_tz)
|
||||||
self._fmt = self.parameter("format", default_format(self.name))
|
self._fmt = self.parameter("format", default_format(self.name))
|
||||||
|
default_timezone = ""
|
||||||
try:
|
try:
|
||||||
self._timezones = self.parameter("timezone", tzlocal.get_localzone().zone).split(",")
|
default_timezone = tzlocal.get_localzone().zone
|
||||||
|
except Exception as e:
|
||||||
|
logging.error('unable to get default timezone: {}'.format(str(e)))
|
||||||
|
try:
|
||||||
|
self._timezones = self.parameter("timezone", default_timezone).split(",")
|
||||||
except:
|
except:
|
||||||
self._timezones = ""
|
self._timezones = [default_timezone]
|
||||||
self._current_tz = 0
|
self._current_tz = 0
|
||||||
|
|
||||||
l = locale.getdefaultlocale()
|
l = locale.getdefaultlocale()
|
||||||
|
@ -63,7 +69,8 @@ class Module(bumblebee.engine.Module):
|
||||||
retval = datetime.datetime.now(tz=tzlocal.get_localzone()).astimezone(tz).strftime(self._fmt)
|
retval = datetime.datetime.now(tz=tzlocal.get_localzone()).astimezone(tz).strftime(self._fmt)
|
||||||
except pytz.exceptions.UnknownTimeZoneError:
|
except pytz.exceptions.UnknownTimeZoneError:
|
||||||
retval = "[Unknown timezone: {}]".format(self._timezones[self._current_tz].strip())
|
retval = "[Unknown timezone: {}]".format(self._timezones[self._current_tz].strip())
|
||||||
except:
|
except Exception as e:
|
||||||
|
logging.error('unable to get time: {}'.format(str(e)))
|
||||||
retval = "[n/a]"
|
retval = "[n/a]"
|
||||||
|
|
||||||
enc = locale.getpreferredencoding()
|
enc = locale.getpreferredencoding()
|
||||||
|
|
Loading…
Reference in a new issue