Skip to content

Commit

Permalink
Add support for providers in OSF (#77)
Browse files Browse the repository at this point in the history
Closes #69
  • Loading branch information
micafer authored Jun 26, 2024
1 parent 1bc2391 commit 0019d7b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
23 changes: 21 additions & 2 deletions datahugger/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,10 @@ class OSFDataset(DatasetDownloader):
REGEXP_ID = r"osf\.io\/(?P<record_id>.*)/"

# the base entry point of the REST API
API_URL = "https://api.osf.io/v2/registrations/"
API_URL = "https://api.osf.io/v2/nodes/"

# the files and metadata about the dataset
API_URL_META = "{api_url}{record_id}/files/osfstorage/?format=jsonapi"
API_URL_META = "{api_url}{record_id}/files/"
META_FILES_JSONPATH = "data[*]"

PAGINATION_JSONPATH = "links.next"
Expand All @@ -343,6 +343,25 @@ class OSFDataset(DatasetDownloader):
ATTR_HASH_JSONPATH = "attributes.extra.hashes.sha256"
ATTR_HASH_TYPE_VALUE = "sha256"

def _get_node_providers(self):
"""Get the providers of a node."""
record_id = self._params["record_id"]
res = requests.get(f"{self.API_URL}/{record_id}/files/")
return set([prov["attributes"]["provider"] for prov in res.json()["data"]])

def _get_files_recursive(self, url, folder_name=None, base_url=None):
files = []
# In case of the top-level folder, we need to get first the providers
if folder_name is None:
for provider in self._get_node_providers():
# and then the files of each provider
files.extend(
super()._get_files_recursive(f"{url}{provider}/", None, base_url)
)
else:
files = super()._get_files_recursive(url, folder_name, base_url)
return files


class ZenodoDataset(DatasetDownloader):
"""Downloader for Zenodo repository.
Expand Down
1 change: 1 addition & 0 deletions tests/test_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
),
("https://doi.org/10.5061/dryad.31zcrjdm5", "ReadmeFile.txt"),
# OSF
("https://osf.io/ews27/", "Cross-comparison/amarlt1"),
("https://osf.io/kq573/", "nest_area_data.xlsx"),
("https://doi.org/10.17605/OSF.IO/KQ573", "nest_area_data.xlsx"),
("https://doi.org/10.17605/OSF.IO/9X6CA", "jobs.sh"),
Expand Down

0 comments on commit 0019d7b

Please sign in to comment.