Skip to content

Commit 879ca83

Browse files
committed
Yet some more fixes for *Zenodo* API changes...
1 parent d8b0620 commit 879ca83

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

colour_datasets/loaders/asano2015.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,3 +342,9 @@ def build_Asano2015(load: bool = True) -> DatasetLoader_Asano2015:
342342
_DATASET_LOADER_ASANO2015.load()
343343

344344
return _DATASET_LOADER_ASANO2015
345+
346+
347+
if __name__ == "__main__":
348+
import colour_datasets
349+
350+
colour_datasets.load("3252742")

colour_datasets/records/tests/test_zenodo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ def test__str__(self):
159159
-----
160160
161161
- camlist&equipment.txt : https://zenodo.org/api/records/3245883/files/\
162-
camlist&equipment.txt
162+
camlist&equipment.txt/content
163163
- camspec_database.txt : https://zenodo.org/api/records/3245883/files/\
164-
camspec_database.txt
165-
- urls.txt : https://zenodo.org/api/records/3245883/files/urls.txt"""
164+
camspec_database.txt/content
165+
- urls.txt : https://zenodo.org/api/records/3245883/files/urls.txt/content"""
166166
)[1:],
167167
)
168168

colour_datasets/records/zenodo.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import json
1515
import os
16+
import re
1617
import shutil
1718
import stat
1819
import tempfile
@@ -204,8 +205,8 @@ def strip_html(text: str) -> str:
204205

205206
files = "\n".join(
206207
[
207-
f"- {file_data['filename']} : {file_data['links']['self']}"
208-
for file_data in sorted(files, key=lambda x: x["filename"])
208+
f'- {file_data["key"]} : {file_data["links"]["self"]}'
209+
for file_data in sorted(files, key=lambda x: x["key"])
209210
]
210211
)
211212

@@ -388,31 +389,29 @@ def pull(self, use_urls_txt_file: bool = True, retries: int = 3):
388389
# given by the content of :attr:`URLS_TXT_FILE` attribute file.
389390
urls_txt = None
390391
for file_data in self.data["files"]:
391-
if file_data["filename"] == self._configuration.urls_txt_file:
392+
if file_data["key"] == self._configuration.urls_txt_file:
392393
urls_txt = file_data
393394
break
394395

395-
def urls_download(urls: Dict, is_content_url=False):
396+
def urls_download(urls: Dict) -> None:
396397
"""Download given urls."""
397398

398399
for url, md5 in urls.items():
400+
filename = re.sub("/content$", "", url)
399401
filename = os.path.join(
400402
downloads_directory,
401403
urllib.parse.unquote( # pyright: ignore
402-
url.split("/")[-1]
404+
filename.split("/")[-1]
403405
),
404406
)
405-
url = ( # noqa: PLW2901
406-
f"{url}/content" if is_content_url else url
407-
)
408407
url_download(url, filename, md5.split(":")[-1], retries)
409408

410409
try:
411410
if use_urls_txt_file and urls_txt:
412411
urls = {}
413412
urls_txt_file = tempfile.NamedTemporaryFile(delete=False).name
414413
url_download(
415-
urls_txt["links"]["download"],
414+
urls_txt["links"]["self"],
416415
urls_txt_file,
417416
urls_txt["checksum"].split(":")[-1],
418417
retries,
@@ -445,7 +444,7 @@ def urls_download(urls: Dict, is_content_url=False):
445444

446445
urls = {}
447446
for file_data in self.data["files"]:
448-
if file_data["filename"] == self._configuration.urls_txt_file:
447+
if file_data["key"] == self._configuration.urls_txt_file:
449448
continue
450449

451450
# TODO: Remove the following space escaping: The new Zenodo API
@@ -457,7 +456,7 @@ def urls_download(urls: Dict, is_content_url=False):
457456

458457
urls[url] = file_data["checksum"].split(":")[-1]
459458

460-
urls_download(urls, is_content_url=True)
459+
urls_download(urls)
461460

462461
deflate_directory = os.path.join(
463462
self.repository, self._configuration.deflate_directory

0 commit comments

Comments
 (0)