From 0306760eb32ea23faaf87e9052306e439a20450a Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Sun, 12 Apr 2020 20:36:32 +0200 Subject: [PATCH] [modules/redshift] No digits for transition anymore Having 2 digits *after* the comma for transitions seems excessive - truncate value at the digit sign. --- modules/core/redshift.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/modules/core/redshift.py b/modules/core/redshift.py index 3224737..b708abb 100644 --- a/modules/core/redshift.py +++ b/modules/core/redshift.py @@ -13,13 +13,9 @@ Parameters: * redshift.lon : longitude if location is set to 'manual' """ +import re import threading -import logging -log = logging.getLogger(__name__) -try: - import requests -except ImportError: - log.warning('unable to import module "requests": Location via IP disabled') +import requests import core.module import core.widget @@ -64,7 +60,8 @@ def get_redshift_value(module): widget.set('state', 'night') else: widget.set('state', 'transition') - widget.set('transition', ' '.join(line.split(' ')[2:])) + match = re.search(r'(\d+)\.\d+% ([a-z]+)', line) + widget.set('transition', '({}% {})'.format(match.group(1), match.group(2))) core.event.trigger('update', [ widget.module().id ], redraw_only=True) class Module(core.module.Module): @@ -73,7 +70,7 @@ class Module(core.module.Module): widget = core.widget.Widget(self.text) super().__init__(config, widget) - self.__thread = threading.Thread(target=get_redshift_value, args=(self,)) + self.__thread = None if self.parameter('location', '') == 'ipinfo': # override lon/lat with ipinfo @@ -97,8 +94,9 @@ class Module(core.module.Module): return val def update(self): - if self.__thread.isAlive(): + if self.__thread is not None and self.__thread.isAlive(): return + self.__thread = threading.Thread(target=get_redshift_value, args=(self,)) self.__thread.start() def state(self, widget):