Skip to content

Commit

Permalink
Fixed a bug that prevented setting a custom , Added logs, Bumped vers…
Browse files Browse the repository at this point in the history
…ion to 0.1.1
  • Loading branch information
DeepSpace2 committed Nov 1, 2020
1 parent 600f60c commit 84d6a58
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions powerline_owmweather/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
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)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 84d6a58

Please sign in to comment.