Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ from dmi_open_data import DMIOpenDataClient, Parameter, ClimateDataParameter, Oc


# Get 10 stations
client = DMIOpenDataClient(api_key=os.getenv('DMI_API_KEY'))
client = DMIOpenDataClient()
stations = client.get_stations(limit=10)

# Get all stations
Expand Down Expand Up @@ -56,7 +56,7 @@ observations = client.get_observations(
limit=1000)

# Init climate data client
climate_data_client = DMIOpenDataClient(api_key=os.getenv('DMI_CLIMATE_DATA_API_KEY'))
climate_data_client = DMIOpenDataClient()

# Get climate data
climate_data = climate_data_client.get_climate_data(
Expand All @@ -68,7 +68,7 @@ climate_data = climate_data_client.get_climate_data(
limit=1000)

# Init oceanographic data client
ocean_data_client = DMIOpenDataClient(api_key=os.getenv('DMI_OCEAN_DATA_API_KEY'))
ocean_data_client = DMIOpenDataClient()

# Get oceanographic data
ocean_data = ocean_data_client.get_ocean_data(
Expand All @@ -79,10 +79,6 @@ ocean_data = ocean_data_client.get_ocean_data(
limit=1000)
```

## API Key

API Key can be obtained for free at the [DMI Open Data](https://confluence.govcloud.dk/pages/viewpage.action?pageId=26476690).

## Tests

Run tests
Expand Down
8 changes: 2 additions & 6 deletions dmi_open_data/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@


class DMIOpenDataClient:
_base_url = "https://dmigw.govcloud.dk/{version}/{api}"
_base_url = "https://opendataapi.dmi.dk/{version}/{api}"

def __init__(self, api_key: str, version: str = "v2"):
if api_key is None:
raise ValueError(f"Invalid value for `api_key`: {api_key}")
def __init__(self, version: str = "v2"):
if version == "v1":
raise ValueError(f"DMI metObs v1 not longer supported")
if version not in ["v2"]:
raise ValueError(f"API version {version} not supported")

self.api_key = api_key
self.version = version

def base_url(self, api: str):
Expand All @@ -36,7 +33,6 @@ def _query(self, api: str, service: str, params: dict[str, Any], **kwargs):
res = requests.get(
url=f"{self.base_url(api=api)}/{service}",
params={
"api-key": self.api_key,
**params,
},
**kwargs,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class TestClient(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.client = DMIOpenDataClient(api_key=os.getenv("DMI_API_KEY"))
cls.client = DMIOpenDataClient()

def test_stations(self):
stations = self.client.get_stations()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_climate_data_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
class TestClient(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.client = DMIOpenDataClient(api_key=os.getenv("DMI_CLIMATE_DATA_API_KEY"))
cls.client = DMIOpenDataClient()

def test_observations(self):
climate_data = self.client.get_climate_data(
parameter=ClimateDataParameter.MeanTemp,
station_id="06184",
station_id="06180",
from_time=datetime(2021, 7, 20),
to_time=datetime(2021, 7, 24),
time_resolution="day",
Expand Down