From 84d6a5804b505dad7f154c7c73939ff33dc56eff Mon Sep 17 00:00:00 2001 From: DeepSpace2 Date: Sun, 1 Nov 2020 02:23:31 +0200 Subject: [PATCH] Fixed a bug that prevented setting a custom , Added logs, Bumped version to 0.1.1 --- README.md | 6 +++++- powerline_owmweather/weather.py | 12 ++++++++++-- setup.py | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7776d9b..06e715a 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,11 @@ The highlight group used is `weather_temp`. ## Changelog -### 0.1.0 +### 0.1.1 - Oct. 31 2020 +* Fixed a bug that prevented setting a custom `ttl_in_minutes` +* Added debug logs + +### 0.1.0 - Oct. 31 2020 Initial release ## TODO diff --git a/powerline_owmweather/weather.py b/powerline_owmweather/weather.py index ce1f854..299c30c 100644 --- a/powerline_owmweather/weather.py +++ b/powerline_owmweather/weather.py @@ -22,10 +22,12 @@ @lru_cache() def _weather(pl, *, openweathermap_api_key, location_query=None, units='C', temp_format='{temp:.0f}', **kwargs): + pl.debug('Called _weather') if not location_query: + pl.debug('Fetching location') location_data = json.loads(urllib_read('https://ipapi.co/json')) location_query = '{}, {}'.format(location_data['city'], location_data['country_code']) - + pl.debug('Fetching weather for {}'.format(location_query)) weather_url = 'https://api.openweathermap.org/data/2.5/weather?q={}&units={}&appid={}'.format(urllib.parse.quote(location_query), temp_units_names.get(units, 'metric'), openweathermap_api_key) raw_response = urllib_read(weather_url) # print(raw_response) @@ -52,4 +54,10 @@ def _weather(pl, *, openweathermap_api_key, location_query=None, units='C', temp ] def weather(*args, **kwargs): - return _weather(*args, ttl_in_minutes=time.time() // (kwargs.get('ttl_in_minutes', 60) * 60), **kwargs) \ No newline at end of file + try: + ttl_in_minutes = kwargs.pop('ttl_in_minutes') + except KeyError: + ttl_in_minutes = 60 + if ttl_in_minutes == 0: + return _weather(*args, ttl=time.time(), **kwargs) + return _weather(*args, ttl=time.time() // (ttl_in_minutes * 60), **kwargs) diff --git a/setup.py b/setup.py index 8fb9c7c..0e3d457 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name = 'powerline-owmweather', description = 'A Powerline segment for fetching and showing the weather in the current location', - version = '0.1.0', + version = '0.1.1', keywords = 'powerline weather segment terminal cli', license = 'MIT', author = 'DeepSpace2',