cloudnet-api-client 0.1.2__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.2 → cloudnet_api_client-0.1.3}/CHANGELOG.md +6 -0
- {cloudnet_api_client-0.1.2 → cloudnet_api_client-0.1.3}/PKG-INFO +1 -1
- {cloudnet_api_client-0.1.2 → cloudnet_api_client-0.1.3}/cloudnet_api_client/client.py +66 -63
- {cloudnet_api_client-0.1.2 → 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.2/cloudnet_api_client/utils.py +0 -21
- cloudnet_api_client-0.1.2/cloudnet_api_client/version.py +0 -1
- {cloudnet_api_client-0.1.2 → cloudnet_api_client-0.1.3}/.github/workflows/publish.yml +0 -0
- {cloudnet_api_client-0.1.2 → cloudnet_api_client-0.1.3}/.github/workflows/test.yml +0 -0
- {cloudnet_api_client-0.1.2 → cloudnet_api_client-0.1.3}/.gitignore +0 -0
- {cloudnet_api_client-0.1.2 → cloudnet_api_client-0.1.3}/.pre-commit-config.yaml +0 -0
- {cloudnet_api_client-0.1.2 → cloudnet_api_client-0.1.3}/LICENSE +0 -0
- {cloudnet_api_client-0.1.2 → cloudnet_api_client-0.1.3}/README.md +0 -0
- {cloudnet_api_client-0.1.2 → cloudnet_api_client-0.1.3}/cloudnet_api_client/__init__.py +0 -0
- {cloudnet_api_client-0.1.2 → cloudnet_api_client-0.1.3}/cloudnet_api_client/dl.py +0 -0
- {cloudnet_api_client-0.1.2 → cloudnet_api_client-0.1.3}/pyproject.toml +0 -0
|
@@ -5,6 +5,12 @@ 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
|
+
|
|
8
14
|
## 0.1.2 – 2025-03-27
|
|
9
15
|
|
|
10
16
|
- Add method to fetch instruments
|
|
@@ -76,6 +76,7 @@ class APIClient:
|
|
|
76
76
|
updated_at_to: DateParam = None,
|
|
77
77
|
instrument_id: QueryParam = None,
|
|
78
78
|
instrument_pid: QueryParam = None,
|
|
79
|
+
model_id: QueryParam = None,
|
|
79
80
|
product: QueryParam = None,
|
|
80
81
|
show_legacy: bool = False,
|
|
81
82
|
) -> list[ProductMetadata]:
|
|
@@ -86,12 +87,20 @@ class APIClient:
|
|
|
86
87
|
"product": product,
|
|
87
88
|
"showLegacy": show_legacy,
|
|
88
89
|
}
|
|
89
|
-
date_params =
|
|
90
|
+
date_params = _mangle_dates(
|
|
90
91
|
date, date_from, date_to, updated_at_from, updated_at_to
|
|
91
92
|
)
|
|
92
93
|
params.update(date_params)
|
|
93
|
-
|
|
94
|
-
|
|
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)
|
|
95
104
|
|
|
96
105
|
def raw_metadata(
|
|
97
106
|
self,
|
|
@@ -109,7 +118,7 @@ class APIClient:
|
|
|
109
118
|
"instrument": instrument_id,
|
|
110
119
|
"instrumentPid": instrument_pid,
|
|
111
120
|
}
|
|
112
|
-
date_params =
|
|
121
|
+
date_params = _mangle_dates(
|
|
113
122
|
date, date_from, date_to, updated_at_from, updated_at_to
|
|
114
123
|
)
|
|
115
124
|
params.update(date_params)
|
|
@@ -162,63 +171,61 @@ class APIClient:
|
|
|
162
171
|
res.raise_for_status()
|
|
163
172
|
return res.json()
|
|
164
173
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
else:
|
|
188
|
-
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)
|
|
189
196
|
else:
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if
|
|
195
|
-
params["
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
|
199
208
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
except ValueError as e:
|
|
209
|
-
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
|
|
210
217
|
|
|
211
218
|
|
|
212
219
|
def _build_objects(res: list[dict], object_type: type[T]) -> list[T]:
|
|
213
220
|
assert is_dataclass(object_type)
|
|
214
221
|
field_names = {f.name for f in fields(object_type)}
|
|
215
|
-
|
|
222
|
+
objects = [
|
|
216
223
|
object_type(
|
|
217
224
|
**{_to_snake(k): v for k, v in obj.items() if _to_snake(k) in field_names}
|
|
218
225
|
)
|
|
219
226
|
for obj in res
|
|
220
227
|
]
|
|
221
|
-
return cast(list[T],
|
|
228
|
+
return cast(list[T], objects)
|
|
222
229
|
|
|
223
230
|
|
|
224
231
|
def _build_raw_meta_objects(res: list[dict]) -> list[RawMetadata]:
|
|
@@ -226,25 +233,21 @@ def _build_raw_meta_objects(res: list[dict]) -> list[RawMetadata]:
|
|
|
226
233
|
return [
|
|
227
234
|
RawMetadata(
|
|
228
235
|
**{_to_snake(k): v for k, v in obj.items() if _to_snake(k) in field_names},
|
|
229
|
-
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
|
+
),
|
|
230
246
|
)
|
|
231
247
|
for obj in res
|
|
232
248
|
]
|
|
233
249
|
|
|
234
250
|
|
|
235
|
-
def _construct_instrument(obj: dict) -> Instrument:
|
|
236
|
-
return 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
|
-
)
|
|
246
|
-
|
|
247
|
-
|
|
248
251
|
def _to_snake(name: str) -> str:
|
|
249
252
|
return re.sub(r"(?<!^)(?=[A-Z])", "_", name).lower()
|
|
250
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.2"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|