From a4ecdd65667fa087816595336579685d01f687cc Mon Sep 17 00:00:00 2001 From: chestm007 Date: Wed, 26 Dec 2018 02:56:33 +1100 Subject: [PATCH] fix #647 weather doesnt run forever if offline on start (#700) * always run init() added online/offline_interval to settings of base weather class and accompanying logic * remove `require(internet)` from `init` methods of both weather modules * ... --- i3pystatus/weather/__init__.py | 12 +++++++++++- i3pystatus/weather/weathercom.py | 1 - i3pystatus/weather/wunderground.py | 1 - 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/i3pystatus/weather/__init__.py b/i3pystatus/weather/__init__.py index 7d6ff43..a8931fa 100644 --- a/i3pystatus/weather/__init__.py +++ b/i3pystatus/weather/__init__.py @@ -171,6 +171,8 @@ class Weather(IntervalModule): 'shown by the module) when refreshing weather data. ' '**NOTE:** Depending on how quickly the update is ' 'performed, the icon may not be displayed.'), + ('online_interval', 'seconds between updates when online (defaults to interval)'), + ('offline_interval', 'seconds between updates when offline (default: 300)'), 'format', ) required = ('backend',) @@ -191,6 +193,8 @@ class Weather(IntervalModule): color = None backend = None interval = 1800 + offline_interval = 300 + online_interval = None refresh_icon = '⟳' format = '{current_temp}{temp_unit}[ {update_error}]' @@ -205,6 +209,9 @@ class Weather(IntervalModule): user_open(self.backend.forecast_url) def init(self): + if self.online_interval is None: + self.online_interval = int(self.interval) + if self.backend is None: raise RuntimeError('A backend is required') @@ -239,6 +246,10 @@ class Weather(IntervalModule): self.thread.start() def update_thread(self): + if internet(): + self.interval = self.online_interval + else: + self.interval = self.offline_interval try: self.check_weather() while True: @@ -253,7 +264,6 @@ class Weather(IntervalModule): ) self.logger.error(msg, exc_info=True) - @require(internet) def check_weather(self): ''' Check the weather using the configured backend diff --git a/i3pystatus/weather/weathercom.py b/i3pystatus/weather/weathercom.py index b7a8ec9..43c5159 100644 --- a/i3pystatus/weather/weathercom.py +++ b/i3pystatus/weather/weathercom.py @@ -166,7 +166,6 @@ class Weathercom(WeatherBackend): # This will be set in the init based on the passed location code forecast_url = None - @require(internet) def init(self): if self.location_code is not None: # Ensure that the location code is a string, in the event that a diff --git a/i3pystatus/weather/wunderground.py b/i3pystatus/weather/wunderground.py index 3c6decc..7a26c16 100644 --- a/i3pystatus/weather/wunderground.py +++ b/i3pystatus/weather/wunderground.py @@ -107,7 +107,6 @@ class Wunderground(WeatherBackend): station_id = None forecast_url = None - @require(internet) def init(self): ''' Use the location_code to perform a geolookup and find the closest