Closed hwiggerm closed 3 years ago
@hwiggerm thanks for tracking this
This is pretty much the desided behaviour ... when you get get the rain dict with
rain_dict = mgr.weather_at_place('Wageningen,NL').weather.rain
then it is up to you to check whether it contains any key or not This is true also for other dicts returned by PyOWM - eg. temperature, wind, etc.
In your very case, you could just do:
rain_dict = mgr.weather_at_place('Wageningen,NL').weather.rain
1hour_rain = rain_dict.get('1h', None) # change None to whatever you want as a default value
3hour_rain = rain_dict.get('3h', None)
Thanks ! let see what happens when we get rain ;-) expect end of the week Have a great day
On Tue, Feb 23, 2021 at 11:06 PM Claudio Sparpaglione < notifications@github.com> wrote:
@hwiggerm https://github.com/hwiggerm thanks for tracking this
This is pretty much the desided behaviour ... when you get get the rain dict with
rain_dict = mgr.weather_at_place('Wageningen,NL').weather.rain
then it is up to you to check whether it contains any key or not This is true also for other dicts returned by PyOWM - eg. temperature, wind, etc.
In your very case, you could just do:
rain_dict = mgr.weather_at_place('Wageningen,NL').weather.rain1hour_rain = rain_dict.get('1h', None) # change None to whatever you want as a default value3hour_rain = rain_dict.get('3h', None)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/csparpa/pyowm/issues/373#issuecomment-784546339, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFO6A4JEN36FJE6HAQ3TQNDTAQREVANCNFSM4X63FAMQ .
used example below, however when there was no rain the dict is empty and code below gives an error message (KeyError: '1h'). Should report '0'
from pyowm.owm import OWM owm = OWM('8db099bc017e2ccd16cbbbacf6690e9f') [...]
Hello You should delete this api key and create a new one ;)
used example below, however when there was no rain the dict is empty and code below gives an error message (KeyError: '1h'). Should report '0'
from pyowm.owm import OWM owm = OWM('8db099bc017e2ccd16cbbbacf0390e9f') mgr = owm.weather_manager()
rain_dict = mgr.weather_at_place('Wageningen,NL').weather.rain print(rain_dict['1h']) print(rain_dict['3h'])