Source code for action0.open_meteo.forecast.operations
# generated by action0-client-openapi v0.1.2 from forecast.yml — do not edit
from __future__ import annotations
import datetime
from typing import Any
from action0.client import JsonOperation
from action0.client import query
from action0.req import Method
from action0.req import Response
from .errors import BadRequestError
from .errors import decode_error
from .models import GetV1ForecastCellSelection
from .models import GetV1ForecastCurrentItem
from .models import GetV1ForecastDailyItem
from .models import GetV1ForecastHourlyItem
from .models import GetV1ForecastMinutely15Item
from .models import GetV1ForecastModelsItem
from .models import GetV1ForecastPrecipitationUnit
from .models import GetV1ForecastResponse
from .models import GetV1ForecastTemperatureUnit
from .models import GetV1ForecastTimeformat
from .models import GetV1ForecastWindSpeedUnit
from .models import get_v1_forecast_error_from_json
from .models import get_v1_forecast_response_from_json
[docs]
class GetV1Forecast(JsonOperation[GetV1ForecastResponse]):
"""
``GET /v1/forecast`` — Open-Meteo Weather Forecast API
Open-Meteo offers free weather forecast APIs for open-source developers and non-commercial use.
"""
method = Method.GET
path = "/v1/forecast"
#: Geographical WGS84 coordinates. Multiple coordinates can be comma separated.
latitude: str = query()
longitude: str = query()
#: A list of weather variables which should be returned.
hourly: list[GetV1ForecastHourlyItem] | None = query(
default=None, serialize=lambda values: ",".join(str(item.value) for item in values)
)
#: A list of daily weather variable aggregations.
daily: list[GetV1ForecastDailyItem] | None = query(
default=None, serialize=lambda values: ",".join(str(item.value) for item in values)
)
#: A list of variables to return for the current conditions.
current: list[GetV1ForecastCurrentItem] | None = query(
default=None, serialize=lambda values: ",".join(str(item.value) for item in values)
)
#: A list of weather variables at 15-minute intervals.
minutely_15: list[GetV1ForecastMinutely15Item] | None = query(
default=None, serialize=lambda values: ",".join(str(item.value) for item in values)
)
elevation: float | None = query(default=None)
temperature_unit: GetV1ForecastTemperatureUnit = query(
default=GetV1ForecastTemperatureUnit.CELSIUS
)
wind_speed_unit: GetV1ForecastWindSpeedUnit = query(default=GetV1ForecastWindSpeedUnit.KMH)
precipitation_unit: GetV1ForecastPrecipitationUnit = query(
default=GetV1ForecastPrecipitationUnit.MM
)
#: If format unixtime is selected, all time values are returned in UNIX epoch time.
timeformat: GetV1ForecastTimeformat = query(default=GetV1ForecastTimeformat.ISO8601)
#: Any IANA time zone name is supported. Use auto to resolve the local time zone.
timezone: str | None = query(default=None)
#: Return past days of data.
past_days: int = query(default=0)
#: Number of forecast days.
forecast_days: int = query(default=7)
past_hours: int | None = query(default=None)
forecast_hours: int | None = query(default=None)
#: Start date of the time interval in ISO 8601 format.
start_date: datetime.date | None = query(default=None)
#: End date of the time interval in ISO 8601 format.
end_date: datetime.date | None = query(default=None)
#: Slope tilt in degrees for global_tilted_irradiance calculation.
tilt: float = query(default=0)
#: Azimuth for global_tilted_irradiance. North=0, East=90, South=180, West=270.
azimuth: float = query(default=0)
#: Grid cell selection preference: land, sea, or nearest.
cell_selection: GetV1ForecastCellSelection | None = query(default=None)
#: Only required for commercial subscriptions.
apikey: str | None = query(default=None)
#: Manually select one or more weather models.
models: list[GetV1ForecastModelsItem] | None = query(
default=None, serialize=lambda values: ",".join(str(item.value) for item in values)
)
[docs]
def check(self, response: Response) -> None:
"""
:param response: the response the backend produced
:raises BadRequestError: for the documented ``400`` answer
:raises APIError: for any other non-2xx status
"""
if response.status == 400:
data = decode_error(response)
if isinstance(data, dict):
message = f"{type(self).__name__}: unexpected status {response.status}"
raise BadRequestError(
f"{message} {response.phrase}".rstrip(),
response=response,
error=get_v1_forecast_error_from_json(data),
)
super().check(response)
[docs]
def load_json(self, data: Any) -> GetV1ForecastResponse:
"""
:param data: the decoded JSON payload
:return: the parsed result
"""
return get_v1_forecast_response_from_json(data)