Skip to content

Commit

Permalink
handle pagination - needed for Stieger2021 ds
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel-Boehm committed Dec 11, 2024
1 parent e52b71d commit a71aaa8
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions moabb/datasets/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,30 +206,39 @@ def fs_issue_request(method, url, headers, data=None, binary=False):

def fs_get_file_list(article_id, version=None):
"""List all the files associated with a given article.
Parameters
----------
article_id : str or int
Figshare article ID
version : str or id, default is None
Figshare article version. If None, selects the most recent version.
Returns
-------
response : dict
HTTP request response as a python dict
"""
fsurl = "https://api.figshare.com/v2"
if version is None:
url = fsurl + "/articles/{}/files".format(article_id)
headers = {"Content-Type": "application/json"}
response = fs_issue_request("GET", url, headers=headers)
return response
else:
url = fsurl + "/articles/{}/versions/{}".format(article_id, version)
headers = {"Content-Type": "application/json"}
request = fs_issue_request("GET", url, headers=headers)
return request["files"]
all_files = []
page = 1

while True:
if version is None:
url = f"{fsurl}/articles/{article_id}/files?page={page}&page_size=100"
headers = {"Content-Type": "application/json"}
response = fs_issue_request("GET", url, headers=headers)

if not response: # If response is empty, we've got all files
break

all_files.extend(response)
page += 1
else:
url = f"{fsurl}/articles/{article_id}/versions/{version}"
headers = {"Content-Type": "application/json"}
request = fs_issue_request("GET", url, headers=headers)
return request["files"]

return all_files


def fs_get_file_hash(filelist):
Expand Down

0 comments on commit a71aaa8

Please sign in to comment.