From b73f6862ae42badc30ba4bd8be672eab82c79148 Mon Sep 17 00:00:00 2001 From: patrick-zippenfenig Date: Thu, 26 Oct 2023 11:05:54 +0200 Subject: [PATCH] update to new structure --- .github/dependabot.yml | 64 +++++++++++++++++------------------- openmeteo_requests/Client.py | 31 ++--------------- tests/test_methods.py | 40 ++++++++++++++-------- 3 files changed, 61 insertions(+), 74 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 7cb0455..9207678 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,35 +1,33 @@ version: 2 updates: -- package-ecosystem: pip - directory: "/" - schedule: - interval: daily - time: "13:00" - open-pull-requests-limit: 10 - reviewers: - - patrick.zippenfenig - allow: - - dependency-type: direct - - dependency-type: indirect - commit-message: - prefix: "fix: " -- package-ecosystem: npm - directory: "/" - schedule: - interval: daily - time: "13:00" - open-pull-requests-limit: 10 - reviewers: - - patrick.zippenfenig - allow: - - dependency-type: direct - - dependency-type: indirect - commit-message: - prefix: "fix: " -- package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: daily - time: "13:00" - commit-message: - prefix: "fix: " + - package-ecosystem: pip + directory: "/" + schedule: + interval: daily + time: "13:00" + open-pull-requests-limit: 10 + reviewers: + - patrick.zippenfenig + allow: + - dependency-type: direct + commit-message: + prefix: "fix: " + - package-ecosystem: npm + directory: "/" + schedule: + interval: daily + time: "13:00" + open-pull-requests-limit: 10 + reviewers: + - patrick.zippenfenig + allow: + - dependency-type: direct + commit-message: + prefix: "fix: " + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: daily + time: "13:00" + commit-message: + prefix: "fix: " diff --git a/openmeteo_requests/Client.py b/openmeteo_requests/Client.py index 3d74dbc..43b6d9b 100644 --- a/openmeteo_requests/Client.py +++ b/openmeteo_requests/Client.py @@ -5,12 +5,7 @@ from typing import TypeVar import requests -from openmeteo_sdk.AirQualityApiResponse import AirQualityApiResponse -from openmeteo_sdk.ClimateApiResponse import ClimateApiResponse -from openmeteo_sdk.EnsembleApiResponse import EnsembleApiResponse -from openmeteo_sdk.FloodApiResponse import FloodApiResponse -from openmeteo_sdk.MarineApiResponse import MarineApiResponse -from openmeteo_sdk.WeatherApiResponse import WeatherApiResponse +from openmeteo_sdk.ApiResponse import ApiResponse T = TypeVar("T") TSession = TypeVar("TSession", bound=requests.Session) @@ -47,29 +42,9 @@ def _get(self, cls: type[T], url: str, params: any) -> list[T]: pos += length + 4 return messages - def weather_api(self, url: str, params: any) -> list[WeatherApiResponse]: + def get(self, url: str, params: any) -> list[ApiResponse]: """Get and decode as weather api""" - return self._get(WeatherApiResponse, url, params) - - def ensemble_api(self, url: str, params: any) -> list[EnsembleApiResponse]: - """Get and decode as ensemble api""" - return self._get(EnsembleApiResponse, url, params) - - def flood_api(self, url: str, params: any) -> list[FloodApiResponse]: - """Get and decode as flood api""" - return self._get(FloodApiResponse, url, params) - - def air_quality_api(self, url: str, params: any) -> list[AirQualityApiResponse]: - """Get and decode as air quality api""" - return self._get(AirQualityApiResponse, url, params) - - def climate_api(self, url: str, params: any) -> list[ClimateApiResponse]: - """Get and decode as climate api""" - return self._get(ClimateApiResponse, url, params) - - def marine_api(self, url: str, params: any) -> list[MarineApiResponse]: - """Get and decode as marine api""" - return self._get(MarineApiResponse, url, params) + return self._get(ApiResponse, url, params) def __del__(self): """cleanup""" diff --git a/tests/test_methods.py b/tests/test_methods.py index 2b5b18e..591f3d3 100644 --- a/tests/test_methods.py +++ b/tests/test_methods.py @@ -2,6 +2,7 @@ from __future__ import annotations import pytest +from openmeteo_sdk.Variable import Variable import openmeteo_requests @@ -19,19 +20,32 @@ def test_fetch_all(): # 'current_weather': 1, } - results = om.weather_api("https://archive-api.open-meteo.com/v1/archive", params=params) - assert len(results) == 3 - result = results[0] - assert result.Latitude() == pytest.approx(52.5) - assert result.Longitude() == pytest.approx(13.4) - result = results[1] - assert result.Latitude() == pytest.approx(48.1) - assert result.Longitude() == pytest.approx(9.3) - result = results[0] - - print(f"Coordinates {result.Latitude()}°E {result.Longitude()}°N {result.Elevation()} m asl") - print(f"Timezone {result.Timezone()} {result.TimezoneAbbreviation()} {result.UtcOffsetSeconds()}") - print(f"Generation time {result.GenerationtimeMs()} ms") + responses = om.get("https://archive-api.open-meteo.com/v1/archive", params=params) + #responses = om.get("http://127.0.0.1:8080/v1/archive", params=params) + assert len(responses) == 3 + response = responses[0] + assert response.Latitude() == pytest.approx(52.5) + assert response.Longitude() == pytest.approx(13.4) + response = responses[1] + assert response.Latitude() == pytest.approx(48.1) + assert response.Longitude() == pytest.approx(9.3) + response = responses[0] + + print(f"Coordinates {response.Latitude()}°E {response.Longitude()}°N {response.Elevation()} m asl") + print(f"Timezone {response.Timezone()} {response.TimezoneAbbreviation()} {response.UtcOffsetSeconds()}") + print(f"Generation time {response.GenerationTimeMilliseconds()} ms") + + hourly = response.Hourly() + hourly_series = list(map(lambda i: hourly.Series(i), range(0, hourly.SeriesLength()))) + + temperature_2m = next(filter(lambda x: x.Variable() == Variable.temperature and x.Altitude() == 2, hourly_series)) + precipitation = next(filter(lambda x: x.Variable() == Variable.precipitation, hourly_series)) + + assert temperature_2m.ValuesLength() == 48 + assert precipitation.ValuesLength() == 48 + + #print(temperature_2m.ValuesAsNumpy()) + #print(precipitation.ValuesAsNumpy()) def test_int_client():