csparpa / pyowm

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

Documentation: need clarification on getting temperature from a forecast object #327

Closed rdthree closed 4 years ago

rdthree commented 4 years ago

I'm having trouble getting the temperature from a forecast object. Specifically, I'm using forecast_at_place

Is this possible in PyOWM 3 or should I be combining this with other parts of the API?

csparpa commented 4 years ago

Hi @originalsurfmex of course it is possible! Take the code here: let me paste it here for you,

from pyowm.owm import OWM
owm = OWM('your-api-key')
mgr = owm.weather_manager()
daily_forecast = mgr.forecast_at_place('Berlin,DE', 'daily').forecast  # this gives you a FORECAST object

The daily_forecast object basically contains a list of Weather objects, on for each of the next days in this case

So you should simply iterate over them this way, and for each one extract the embedded temperature data:

for weather in daily_forecast:
    print(weather.temperature(unit='celsius')  # can be also kelvin and fahrenheit

Could this work out to you ? Let me know

rdthree commented 4 years ago

Got it! I wasn't adding the unit so it was coming in blank. Thanks!