Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle pagination - needed for Stieger2021 ds #674

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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