csparpa / pyowm

A Python wrapper around the OpenWeatherMap web API
https://pyowm.readthedocs.io
MIT License
789 stars 171 forks source link

observation.weather.wind not working as described #333

Closed driesvanspauwen closed 4 years ago

driesvanspauwen commented 4 years ago

Problem According to the guide on the pyowm github page following command: observation.weather.wind should return something like: {'speed': 4.6, 'deg': 330} from which people are able to retract the wind speed and degree using observation.weather.wind['speed']

Now when I use the .wind command and print it, it returns: <bound method Weather.wind of <pyowm.weatherapi25.weather.Weather - reference_time=2020-08-18 15:50:11+00, status=clouds, detailed_status=broken clouds>> So that corresponds to the status of the weather, but has nothing to do with the wind speed/degree. It's also in a format in which it's not possible to retract any data from it.

In all tutorials I could find on the internet this command was either not used or worked as described on the GitHub page, but I believe recently there have been some changes in pyowm that I can't really find a report of.

Question So my question is which code I should use to get the current wind speed. Thanks in advance!

My code: from pyowm import OWM

owm = OWM(owm_apikey)

mgr = owm.weather_manager() observation = mgr.weather_at_place('Leuven,Belgium') w = observation.weather

temp = w.temperature('celsius') status = w.detailed_status wind = w.wind humidity = w.humidity

print(wind['speed'])

csparpa commented 4 years ago

Hi @driesvanspauwen the answer is easy: you're calling something like this:

observation.wind["speed"]

but instead should call:

observation.wind()["speed"]

As you can see here: https://github.com/csparpa/pyowm/blob/e35446ebe081c0b14a25dca0f7f8105836745b04/pyowm/weatherapi25/weather.py#L166 you retrieve wind data from the weather object by using a function , not by accessing a property

I'm closing this for the moment, feel free to reopen the issue if you still have problems with the code