Skip to content

Commit

Permalink
helpers: drop legacy code
Browse files Browse the repository at this point in the history
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
  • Loading branch information
Noltari committed Feb 23, 2024
1 parent e03ae73 commit 88ead54
Showing 1 changed file with 1 addition and 58 deletions.
59 changes: 1 addition & 58 deletions aemet_opendata/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@
from typing import Any
from zoneinfo import ZoneInfo

from .const import (
AEMET_ATTR_PERIOD,
AEMET_ATTR_VALUE,
API_ID_PFX,
API_PERIOD_24H,
API_PERIOD_FULL_DAY,
API_PERIOD_SPLIT,
)
from .const import API_ID_PFX

TZ_UTC = ZoneInfo("UTC")

Expand All @@ -31,56 +24,6 @@ def get_current_datetime(tz: ZoneInfo = TZ_UTC) -> datetime:
return datetime.now(tz=tz).replace(minute=0, second=0, microsecond=0)


def get_forecast_day_value(
values: dict[str, Any] | list[Any], key: str = AEMET_ATTR_VALUE
) -> Any:
"""Get day value from forecast."""
if isinstance(values, list):
if len(values) > 1:
for value in values:
if key not in value:
continue
if value[AEMET_ATTR_PERIOD] == API_PERIOD_FULL_DAY:
return value[key]
else:
if key in values[0]:
return values[0][key]
if isinstance(values, dict):
if key in values:
return values[key]
return None


def get_forecast_hour_value(values: Any, hour: int, key: str = AEMET_ATTR_VALUE) -> Any:
"""Get hour value from forecast."""
for value in values:
if key not in value:
continue
if int(value[AEMET_ATTR_PERIOD]) == hour:
return None if not value[key] else value[key]
return None


def get_forecast_interval_value(
values: Any, hour: int, key: str = AEMET_ATTR_VALUE
) -> Any:
"""Get hour value from forecast interval."""
for value in values:
if key not in value:
continue
period_start = int(value[AEMET_ATTR_PERIOD][0:API_PERIOD_SPLIT])
period_end = int(
value[AEMET_ATTR_PERIOD][API_PERIOD_SPLIT : API_PERIOD_SPLIT * 2]
)
if period_end < period_start:
period_end = period_end + API_PERIOD_24H
if hour == 0:
hour = hour + API_PERIOD_24H
if period_start <= hour < period_end:
return None if not value[key] else value[key]
return None


def split_coordinate(coordinate: str) -> str:
"""Split climatological values station coordinate."""
coord_deg = coordinate[0:2]
Expand Down

0 comments on commit 88ead54

Please sign in to comment.