From 30118d5ca80efb26d3653e2d6a15ed2b2867eabc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Wed, 23 Aug 2023 12:25:04 +0200 Subject: [PATCH] interface: add raw API data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- aemet_opendata/interface.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/aemet_opendata/interface.py b/aemet_opendata/interface.py index 874c873..63e1c88 100644 --- a/aemet_opendata/interface.py +++ b/aemet_opendata/interface.py @@ -23,6 +23,10 @@ API_URL, ATTR_DATA, ATTR_RESPONSE, + RAW_FORECAST_DAILY, + RAW_FORECAST_HOURLY, + RAW_STATIONS, + RAW_TOWNS, ) from .exceptions import AemetError, AuthError, TooManyRequests from .helpers import parse_station_coordinates, parse_town_code @@ -46,6 +50,12 @@ def __init__( options: ConnectionOptions, ) -> None: """Init AEMET OpenData API.""" + self._api_raw_data: dict[str, Any] = { + RAW_FORECAST_DAILY: {}, + RAW_FORECAST_HOURLY: {}, + RAW_STATIONS: {}, + RAW_TOWNS: {}, + } self.aiohttp_session = aiohttp_session self.dist_hp: bool = False self.headers: dict[str, Any] = { @@ -114,6 +124,10 @@ async def api_data(self, url: str) -> dict[str, Any]: return cast(dict[str, Any], resp_json) + def raw_data(self) -> dict[str, Any]: + """Return raw AEMET OpenData API data.""" + return self._api_raw_data + def calc_distance( self, start: tuple[float, float], end: tuple[float, float] ) -> Distance: @@ -196,9 +210,11 @@ async def get_conventional_observation_station_data( self, station: str, fetch_data: bool = True ) -> dict[str, Any]: """Get data from conventional observation station.""" - return await self.api_call( + res await self.api_call( f"observacion/convencional/datos/estacion/{station}", fetch_data ) + self._api_raw_data[RAW_STATIONS][station] = res + return res async def get_lightnings_map(self) -> dict[str, Any]: """Get map with lightning falls (last 6h).""" @@ -208,23 +224,29 @@ async def get_specific_forecast_town_daily( self, town: str, fetch_data: bool = True ) -> dict[str, Any]: """Get daily forecast for specific town (daily).""" - return await self.api_call( + res await self.api_call( f"prediccion/especifica/municipio/diaria/{parse_town_code(town)}", fetch_data, ) + self._api_raw_data[RAW_FORECAST_DAILY][town] = res + return res async def get_specific_forecast_town_hourly( self, town: str, fetch_data: bool = True ) -> dict[str, Any]: """Get hourly forecast for specific town (hourly).""" - return await self.api_call( + res await self.api_call( f"prediccion/especifica/municipio/horaria/{parse_town_code(town)}", fetch_data, ) + self._api_raw_data[RAW_FORECAST_HOURLY][town] = res + return res async def get_town(self, town: str) -> dict[str, Any]: """Get information about specific town.""" - return await self.api_call(f"maestro/municipio/{town}") + res await self.api_call(f"maestro/municipio/{town}") + self._api_raw_data[RAW_TOWNS][town] = res + return res async def get_town_by_coordinates( self, latitude: float, longitude: float