[modules/datetimetz] quotes

This commit is contained in:
tobi-wan-kenobi 2020-04-25 10:41:09 +02:00
parent 99aadc9188
commit 80fed80847

View file

@ -28,11 +28,11 @@ import bumblebee.output
import bumblebee.engine import bumblebee.engine
def default_format(module): def default_format(module):
default = "%x %X %Z" default = '%x %X %Z'
if module == "datetz": if module == 'datetz':
default = "%x %Z" default = '%x %Z'
if module == "timetz": if module == 'timetz':
default = "%X %Z" default = '%X %Z'
return default return default
class Module(bumblebee.engine.Module): class Module(bumblebee.engine.Module):
@ -41,14 +41,14 @@ class Module(bumblebee.engine.Module):
bumblebee.output.Widget(full_text=self.get_time)) bumblebee.output.Widget(full_text=self.get_time))
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 = "" default_timezone = ''
try: try:
default_timezone = tzlocal.get_localzone().zone default_timezone = tzlocal.get_localzone().zone
except Exception as e: except Exception as e:
logging.error('unable to get default timezone: {}'.format(str(e))) logging.error('unable to get default timezone: {}'.format(str(e)))
try: try:
self._timezones = self.parameter("timezone", default_timezone).split(",") self._timezones = self.parameter('timezone', default_timezone).split(',')
except: except:
self._timezones = [default_timezone] self._timezones = [default_timezone]
self._current_tz = 0 self._current_tz = 0
@ -56,9 +56,9 @@ class Module(bumblebee.engine.Module):
l = locale.getdefaultlocale() l = locale.getdefaultlocale()
if not l or l == (None, None): if not l or l == (None, None):
l = ('en_US', 'UTF-8') l = ('en_US', 'UTF-8')
lcl = self.parameter("locale", ".".join(l)) lcl = self.parameter('locale', '.'.join(l))
try: try:
locale.setlocale(locale.LC_TIME, lcl.split(".")) locale.setlocale(locale.LC_TIME, lcl.split('.'))
except Exception: except Exception:
locale.setlocale(locale.LC_TIME, ('en_US', 'UTF-8')) locale.setlocale(locale.LC_TIME, ('en_US', 'UTF-8'))
@ -68,13 +68,13 @@ class Module(bumblebee.engine.Module):
tz = pytz.timezone(self._timezones[self._current_tz].strip()) tz = pytz.timezone(self._timezones[self._current_tz].strip())
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 Exception as e: except Exception as e:
logging.error('unable to get time: {}'.format(str(e))) logging.error('unable to get time: {}'.format(str(e)))
retval = "[n/a]" retval = '[n/a]'
enc = locale.getpreferredencoding() enc = locale.getpreferredencoding()
if hasattr(retval, "decode"): if hasattr(retval, 'decode'):
return retval.decode(enc) return retval.decode(enc)
return retval return retval