Skip to content

Commit

Permalink
update to new structure
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-zippenfenig committed Oct 26, 2023
1 parent 15e7ac9 commit b73f686
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 74 deletions.
64 changes: 31 additions & 33 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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: "
31 changes: 3 additions & 28 deletions openmeteo_requests/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"""
Expand Down
40 changes: 27 additions & 13 deletions tests/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import pytest
from openmeteo_sdk.Variable import Variable

import openmeteo_requests

Expand All @@ -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())))

Check failure on line 39 in tests/test_methods.py

View workflow job for this annotation

GitHub Actions / validation / validation (pytest, -m not integration and not gpu)

test_fetch_all AttributeError: 'NoneType' object has no attribute '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():
Expand Down

0 comments on commit b73f686

Please sign in to comment.