Skip to content

Commit

Permalink
docs: Add another locationforecast example
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroWave022 committed Oct 10, 2023
1 parent e454559 commit 732ae1d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/locationforecast/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,28 @@ Getting future weather predictions
expected_temp = next_6_hrs.details.air_temperature # This value may be None, if no value is received from the API
print(f"In the next 6 hours, the expected temperature is {expected_temp} °C")
Handling possible :class:`None` values:

.. code-block:: python
# Full weather data for Oslo, Norway.
forecast = my_client.get_forecast(59.91, 10.75)
forecast_now = forecast.now()
# A ForecastFuture dataclass storing info about the weather in 6 hours
next_6_hrs = forecast_now.next_6_hours
expected_temp = next_6_hrs.details.air_temperature # This value may be None, if no value is received from the API
if expected_temp is not None:
print(f"In the next 6 hours, the expected temperature is {expected_temp} °C")
else:
min_temp = next_6_hrs.details.air_temperature_min
max_temp = next_6_hrs.details.air_temperature_max
if min_temp is not None and max_temp is not None:
print(f"In the next 6 hours, the expected temperature is between {min_temp} °C and {max_temp} °C")
else:
print("No air temperature value was received from the API.")

0 comments on commit 732ae1d

Please sign in to comment.