Skip to content

v0.4.0

Latest
Compare
Choose a tag to compare
@ZeroWave022 ZeroWave022 released this 13 Oct 21:15
· 1 commit to main since this release
713d080

Rewrite to more developer-friendly usage

Multiple parts of the package have been rewritten to use classes and dataclasses instead of dicts. This results in easier usage and requires less code for the same effect(s).

Locationforecast

Data is easier to access.

Old usage example in v0.3.0:

# Full weather data for Oslo, Norway.
forecast = my_client.get_forecast(59.91, 10.75, "compact")

now = forecast["properties"]["timeseries"][0]["data"]

next_6_hours = now["next_6_hours"]["details"]

print("Air temperature next 6 hours is predicted to be between:")
print(f"{next_6_hours['air_temperature_min']} °C and {next_6_hours['air_temperature_max']} °C")

In v0.4.0:

# Full weather data for Oslo, Norway.
forecast = my_client.get_forecast(59.91, 10.75, "compact")

now = forecast.now()

air_temp_min = now.next_6_hours.details.air_temperature_min
air_temp_max = now.next_6_hours.details.air_temperature_max

print("Air temperature next 6 hours is predicted to be between:")
print(f"{air_temp_min} °C and {air_temp_max} °C")

Other shortcuts, such as getting the current air temperature for a location, are still available (see Locationforecast.get_air_temperature)

See other examples in the docs

Textforecast

Data is easier to access, the structure has been flattened.

Old usage example in v0.3.0:

land_overview = my_client.get_forecasts("landoverview")

newest_forecast = land_overview["time"][0]["forecasttype"]

first_location = newest_forecast["location"][0]

print(f"The forecast for the first location is: {first_location.text}")

In v0.4.0:

land_overview = my_client.get_forecasts("landoverview")

forecast_now = land_overview.now()

# Not really that useful to get the first location, so why not get a specific one?
forecast_east = forecast_now.locations.get("Østlandet")

if forecast_east:
    print(f"The forecast for Østlandet is: {forecast_east.text}")
else:
    print("Sorry, couldn't get the forecast for Østlandet!")

# Not sure which locations are available in the forecast you received? Use TextForecastLocations.names
locations = forecast_now.locations.names

print(f"Available locations are {', '.join(locations)}")

See other examples in the docs

Radar, Sunrise and Geosatellite

These MET API products have also received improvements when using yr-weather.
For details, check the examples in the documentation for the respective product.

Other changes

  • The project status has developed: alpha -> beta
  • Testing using pytest added
  • Added support for mypy

Available on PyPi.

Full Changelog: v0.3.0...v0.4.0