cloudnet-api-client 0.1.1__tar.gz → 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cloudnet_api_client-0.1.1 → cloudnet_api_client-0.1.3}/CHANGELOG.md +10 -0
- {cloudnet_api_client-0.1.1 → cloudnet_api_client-0.1.3}/PKG-INFO +5 -1
- {cloudnet_api_client-0.1.1 → cloudnet_api_client-0.1.3}/README.md +4 -0
- {cloudnet_api_client-0.1.1 → cloudnet_api_client-0.1.3}/cloudnet_api_client/client.py +82 -63
- {cloudnet_api_client-0.1.1 → cloudnet_api_client-0.1.3}/cloudnet_api_client/containers.py +1 -1
- cloudnet_api_client-0.1.3/cloudnet_api_client/py.typed +0 -0
- cloudnet_api_client-0.1.3/cloudnet_api_client/utils.py +19 -0
- cloudnet_api_client-0.1.3/cloudnet_api_client/version.py +1 -0
- cloudnet_api_client-0.1.1/cloudnet_api_client/utils.py +0 -21
- cloudnet_api_client-0.1.1/cloudnet_api_client/version.py +0 -1
- {cloudnet_api_client-0.1.1 → cloudnet_api_client-0.1.3}/.github/workflows/publish.yml +0 -0
- {cloudnet_api_client-0.1.1 → cloudnet_api_client-0.1.3}/.github/workflows/test.yml +0 -0
- {cloudnet_api_client-0.1.1 → cloudnet_api_client-0.1.3}/.gitignore +0 -0
- {cloudnet_api_client-0.1.1 → cloudnet_api_client-0.1.3}/.pre-commit-config.yaml +0 -0
- {cloudnet_api_client-0.1.1 → cloudnet_api_client-0.1.3}/LICENSE +0 -0
- {cloudnet_api_client-0.1.1 → cloudnet_api_client-0.1.3}/cloudnet_api_client/__init__.py +0 -0
- {cloudnet_api_client-0.1.1 → cloudnet_api_client-0.1.3}/cloudnet_api_client/dl.py +0 -0
- {cloudnet_api_client-0.1.1 → cloudnet_api_client-0.1.3}/pyproject.toml +0 -0
|
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## 0.1.3 – 2025-03-31
|
|
9
|
+
|
|
10
|
+
- Add py.typed
|
|
11
|
+
- Add optimum model to metadata response
|
|
12
|
+
- Add model_id parameter
|
|
13
|
+
|
|
14
|
+
## 0.1.2 – 2025-03-27
|
|
15
|
+
|
|
16
|
+
- Add method to fetch instruments
|
|
17
|
+
|
|
8
18
|
## 0.1.1 – 2025-03-27
|
|
9
19
|
|
|
10
20
|
- Add `updated_at_from` and `updated_at_to` parameters
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cloudnet-api-client
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: Cloudnet API client
|
|
5
5
|
Author-email: Simo Tukiainen <simo.tukiainen@fmi.fi>
|
|
6
6
|
License-File: LICENSE
|
|
@@ -127,6 +127,10 @@ Parameters:
|
|
|
127
127
|
| ---- | ---------------- | ----------------------------------------- | ------- |
|
|
128
128
|
| type | `str` or `[str]` | "instrument", "geophysical", "evaluation" | `None` |
|
|
129
129
|
|
|
130
|
+
### `APIClient().instruments()` → `[Instrument]`
|
|
131
|
+
|
|
132
|
+
Fetch cloudnet instruments.
|
|
133
|
+
|
|
130
134
|
### `cloudnet_api_client.download([Metadata])`
|
|
131
135
|
|
|
132
136
|
Download files from the fetched metadata.
|
|
@@ -102,6 +102,10 @@ Parameters:
|
|
|
102
102
|
| ---- | ---------------- | ----------------------------------------- | ------- |
|
|
103
103
|
| type | `str` or `[str]` | "instrument", "geophysical", "evaluation" | `None` |
|
|
104
104
|
|
|
105
|
+
### `APIClient().instruments()` → `[Instrument]`
|
|
106
|
+
|
|
107
|
+
Fetch cloudnet instruments.
|
|
108
|
+
|
|
105
109
|
### `cloudnet_api_client.download([Metadata])`
|
|
106
110
|
|
|
107
111
|
Download files from the fetched metadata.
|
|
@@ -50,6 +50,22 @@ class APIClient:
|
|
|
50
50
|
data = [obj for obj in data if any(t in obj.type for t in type)]
|
|
51
51
|
return data
|
|
52
52
|
|
|
53
|
+
def instruments(self) -> list[Instrument]:
|
|
54
|
+
res = self._get_response("instrument-pids")
|
|
55
|
+
return [
|
|
56
|
+
Instrument(
|
|
57
|
+
instrument_id=obj["instrument"]["id"],
|
|
58
|
+
model=obj["model"],
|
|
59
|
+
type=obj["type"],
|
|
60
|
+
uuid=obj["uuid"],
|
|
61
|
+
pid=obj["pid"],
|
|
62
|
+
owners=obj["owners"],
|
|
63
|
+
serial_number=obj["serialNumber"],
|
|
64
|
+
name=obj["name"],
|
|
65
|
+
)
|
|
66
|
+
for obj in res
|
|
67
|
+
]
|
|
68
|
+
|
|
53
69
|
def metadata(
|
|
54
70
|
self,
|
|
55
71
|
site_id: str,
|
|
@@ -60,6 +76,7 @@ class APIClient:
|
|
|
60
76
|
updated_at_to: DateParam = None,
|
|
61
77
|
instrument_id: QueryParam = None,
|
|
62
78
|
instrument_pid: QueryParam = None,
|
|
79
|
+
model_id: QueryParam = None,
|
|
63
80
|
product: QueryParam = None,
|
|
64
81
|
show_legacy: bool = False,
|
|
65
82
|
) -> list[ProductMetadata]:
|
|
@@ -70,12 +87,20 @@ class APIClient:
|
|
|
70
87
|
"product": product,
|
|
71
88
|
"showLegacy": show_legacy,
|
|
72
89
|
}
|
|
73
|
-
date_params =
|
|
90
|
+
date_params = _mangle_dates(
|
|
74
91
|
date, date_from, date_to, updated_at_from, updated_at_to
|
|
75
92
|
)
|
|
76
93
|
params.update(date_params)
|
|
77
|
-
|
|
78
|
-
|
|
94
|
+
files_res = self._get_response("files", params)
|
|
95
|
+
|
|
96
|
+
# Add model files if requested
|
|
97
|
+
if not product or "model" in product:
|
|
98
|
+
for key in ("showLegacy", "product", "instrument", "instrumentPid"):
|
|
99
|
+
del params[key]
|
|
100
|
+
params["model"] = model_id
|
|
101
|
+
files_res += self._get_response("model-files", params)
|
|
102
|
+
|
|
103
|
+
return _build_objects(files_res, ProductMetadata)
|
|
79
104
|
|
|
80
105
|
def raw_metadata(
|
|
81
106
|
self,
|
|
@@ -93,7 +118,7 @@ class APIClient:
|
|
|
93
118
|
"instrument": instrument_id,
|
|
94
119
|
"instrumentPid": instrument_pid,
|
|
95
120
|
}
|
|
96
|
-
date_params =
|
|
121
|
+
date_params = _mangle_dates(
|
|
97
122
|
date, date_from, date_to, updated_at_from, updated_at_to
|
|
98
123
|
)
|
|
99
124
|
params.update(date_params)
|
|
@@ -146,63 +171,61 @@ class APIClient:
|
|
|
146
171
|
res.raise_for_status()
|
|
147
172
|
return res.json()
|
|
148
173
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
else:
|
|
172
|
-
raise ValueError("Invalid date format")
|
|
174
|
+
|
|
175
|
+
def _mangle_dates(
|
|
176
|
+
date: DateParam,
|
|
177
|
+
date_from: DateParam,
|
|
178
|
+
date_to: DateParam,
|
|
179
|
+
updated_at_from: DateParam,
|
|
180
|
+
updated_at_to: DateParam,
|
|
181
|
+
) -> dict:
|
|
182
|
+
params = {}
|
|
183
|
+
if isinstance(date, datetime.date):
|
|
184
|
+
params["date"] = date
|
|
185
|
+
elif isinstance(date, str):
|
|
186
|
+
if re.fullmatch(r"\d{4}-\d{2}-\d{2}", date):
|
|
187
|
+
params["date"] = _parse_date(date)
|
|
188
|
+
elif re.fullmatch(r"\d{4}-\d{2}", date):
|
|
189
|
+
date = datetime.datetime.strptime(date, "%Y-%m")
|
|
190
|
+
last_day_number = calendar.monthrange(date.year, date.month)[1]
|
|
191
|
+
params["dateFrom"] = datetime.date(date.year, date.month, 1)
|
|
192
|
+
params["dateTo"] = datetime.date(date.year, date.month, last_day_number)
|
|
193
|
+
elif re.fullmatch(r"\d{4}", date):
|
|
194
|
+
params["dateFrom"] = datetime.date(int(date), 1, 1)
|
|
195
|
+
params["dateTo"] = datetime.date(int(date), 12, 31)
|
|
173
196
|
else:
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if
|
|
179
|
-
params["
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
197
|
+
raise ValueError("Invalid date format")
|
|
198
|
+
else:
|
|
199
|
+
if date_from:
|
|
200
|
+
params["dateFrom"] = _parse_date(date_from)
|
|
201
|
+
if date_to:
|
|
202
|
+
params["dateTo"] = _parse_date(date_to)
|
|
203
|
+
if updated_at_from:
|
|
204
|
+
params["updatedAtFrom"] = _parse_date(updated_at_from)
|
|
205
|
+
if updated_at_to:
|
|
206
|
+
params["updatedAtTo"] = _parse_date(updated_at_to)
|
|
207
|
+
return params
|
|
183
208
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
except ValueError as e:
|
|
193
|
-
raise ValueError(f"Invalid date format: {date}") from e
|
|
209
|
+
|
|
210
|
+
def _parse_date(date: str | datetime.date) -> datetime.date:
|
|
211
|
+
if isinstance(date, datetime.date):
|
|
212
|
+
return date
|
|
213
|
+
try:
|
|
214
|
+
return datetime.datetime.strptime(date, "%Y-%m-%d").date()
|
|
215
|
+
except ValueError as e:
|
|
216
|
+
raise ValueError(f"Invalid date format: {date}") from e
|
|
194
217
|
|
|
195
218
|
|
|
196
219
|
def _build_objects(res: list[dict], object_type: type[T]) -> list[T]:
|
|
197
220
|
assert is_dataclass(object_type)
|
|
198
221
|
field_names = {f.name for f in fields(object_type)}
|
|
199
|
-
|
|
222
|
+
objects = [
|
|
200
223
|
object_type(
|
|
201
224
|
**{_to_snake(k): v for k, v in obj.items() if _to_snake(k) in field_names}
|
|
202
225
|
)
|
|
203
226
|
for obj in res
|
|
204
227
|
]
|
|
205
|
-
return cast(list[T],
|
|
228
|
+
return cast(list[T], objects)
|
|
206
229
|
|
|
207
230
|
|
|
208
231
|
def _build_raw_meta_objects(res: list[dict]) -> list[RawMetadata]:
|
|
@@ -210,25 +233,21 @@ def _build_raw_meta_objects(res: list[dict]) -> list[RawMetadata]:
|
|
|
210
233
|
return [
|
|
211
234
|
RawMetadata(
|
|
212
235
|
**{_to_snake(k): v for k, v in obj.items() if _to_snake(k) in field_names},
|
|
213
|
-
instrument=
|
|
236
|
+
instrument=Instrument(
|
|
237
|
+
instrument_id=obj["instrumentInfo"]["instrumentId"],
|
|
238
|
+
model=obj["instrumentInfo"]["model"],
|
|
239
|
+
type=obj["instrumentInfo"]["type"],
|
|
240
|
+
uuid=obj["instrumentInfo"]["uuid"],
|
|
241
|
+
pid=obj["instrumentInfo"]["pid"],
|
|
242
|
+
owners=obj["instrumentInfo"]["owners"],
|
|
243
|
+
serial_number=obj["instrumentInfo"]["serialNumber"],
|
|
244
|
+
name=obj["instrumentInfo"]["name"],
|
|
245
|
+
),
|
|
214
246
|
)
|
|
215
247
|
for obj in res
|
|
216
248
|
]
|
|
217
249
|
|
|
218
250
|
|
|
219
|
-
def _construct_instrument(obj: dict) -> Instrument:
|
|
220
|
-
return Instrument(
|
|
221
|
-
instrument_id=obj["instrumentInfo"]["instrumentId"],
|
|
222
|
-
model=obj["instrumentInfo"]["model"],
|
|
223
|
-
type=obj["instrumentInfo"]["type"],
|
|
224
|
-
uuid=obj["instrumentInfo"]["uuid"],
|
|
225
|
-
pid=obj["instrumentInfo"]["pid"],
|
|
226
|
-
owners=obj["instrumentInfo"]["owners"],
|
|
227
|
-
serial_number=obj["instrumentInfo"]["serialNumber"],
|
|
228
|
-
name=obj["instrumentInfo"]["name"],
|
|
229
|
-
)
|
|
230
|
-
|
|
231
|
-
|
|
232
251
|
def _to_snake(name: str) -> str:
|
|
233
252
|
return re.sub(r"(?<!^)(?=[A-Z])", "_", name).lower()
|
|
234
253
|
|
|
@@ -3,7 +3,7 @@ from dataclasses import dataclass
|
|
|
3
3
|
from typing import Literal
|
|
4
4
|
|
|
5
5
|
SITE_TYPE = Literal["cloudnet", "model", "hidden", "campaign"]
|
|
6
|
-
PRODUCT_TYPE = Literal["instrument", "geophysical", "evaluation"]
|
|
6
|
+
PRODUCT_TYPE = Literal["instrument", "geophysical", "evaluation", "model"]
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
@dataclass(frozen=True, slots=True)
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import hashlib
|
|
2
|
+
from os import PathLike
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def sha256sum(filename: str | PathLike) -> str:
|
|
7
|
+
return _calc_hash_sum(filename, "sha256")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def md5sum(filename: str | PathLike) -> str:
|
|
11
|
+
return _calc_hash_sum(filename, "md5")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _calc_hash_sum(filename: str | PathLike, method: Literal["sha256", "md5"]) -> str:
|
|
15
|
+
hash_sum = getattr(hashlib, method)()
|
|
16
|
+
with open(filename, "rb") as f:
|
|
17
|
+
for byte_block in iter(lambda: f.read(4096), b""):
|
|
18
|
+
hash_sum.update(byte_block)
|
|
19
|
+
return hash_sum.hexdigest()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.3"
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import base64
|
|
2
|
-
import hashlib
|
|
3
|
-
import os
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def sha256sum(filename: str | os.PathLike) -> str:
|
|
7
|
-
return _calc_hash_sum(filename, "sha256", is_base64=False)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def md5sum(filename: str | os.PathLike, *, is_base64: bool = False) -> str:
|
|
11
|
-
return _calc_hash_sum(filename, "md5", is_base64=is_base64)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def _calc_hash_sum(filename, method, *, is_base64: bool) -> str:
|
|
15
|
-
hash_sum = getattr(hashlib, method)()
|
|
16
|
-
with open(filename, "rb") as f:
|
|
17
|
-
for byte_block in iter(lambda: f.read(4096), b""):
|
|
18
|
-
hash_sum.update(byte_block)
|
|
19
|
-
if is_base64:
|
|
20
|
-
return base64.encodebytes(hash_sum.digest()).decode("utf-8").strip()
|
|
21
|
-
return hash_sum.hexdigest()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.1.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|