From 933dcd1060cf547f82f21e54945b650857b9dae4 Mon Sep 17 00:00:00 2001 From: Patrick Zippenfenig Date: Wed, 7 Feb 2024 14:31:13 +0100 Subject: [PATCH] feat: Allow selection of method to use POST (#40) * feat: Allow selection of method to use POST * fix test --- openmeteo_requests/Client.py | 8 ++++---- tests/test_methods.py | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/openmeteo_requests/Client.py b/openmeteo_requests/Client.py index a7f8425..ad6272a 100644 --- a/openmeteo_requests/Client.py +++ b/openmeteo_requests/Client.py @@ -21,10 +21,10 @@ class Client: def __init__(self, session: TSession | None = None): self.session = session or requests.Session() - def _get(self, cls: type[T], url: str, params: any) -> list[T]: + def _get(self, cls: type[T], url: str, params: any, method: str) -> list[T]: params["format"] = "flatbuffers" - response = self.session.get(url, params=params) + response = self.session.request(method, url, params=params) if response.status_code in [400, 429]: response_body = response.json() raise OpenMeteoRequestsError(response_body) @@ -42,9 +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 weather_api(self, url: str, params: any, method: str = "GET") -> list[WeatherApiResponse]: """Get and decode as weather api""" - return self._get(WeatherApiResponse, url, params) + return self._get(WeatherApiResponse, url, params, method) def __del__(self): """cleanup""" diff --git a/tests/test_methods.py b/tests/test_methods.py index ac3a8d2..f0e589a 100644 --- a/tests/test_methods.py +++ b/tests/test_methods.py @@ -15,6 +15,7 @@ def test_fetch_all(): "hourly": ["temperature_2m", "precipitation"], "start_date": "2023-08-01", "end_date": "2023-08-02", + "models": "era5_seamless" # 'timezone': 'auto', # 'current': ['temperature_2m','precipitation'], # 'current_weather': 1,