Created
June 28, 2021 18:31
-
-
Save jochenklar/6acfb42a1931aa907cd846e063bd2b73 to your computer and use it in GitHub Desktop.
Upload script for zenodo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# needs to be installed with e.g. `pip install requests` | |
import requests | |
from pathlib import Path | |
access_token = '<access_token>' | |
url = 'https://zenodo.org/api/deposit/depositions/<id>' | |
path = Path('/path/to/the/files') | |
files = [ | |
'file1.zip', | |
... | |
] | |
params = {'access_token': access_token} | |
headers = {'Content-Type': 'application/json'} | |
response = requests.get(url, params=params, headers=headers) | |
data = response.json() | |
bucket_url = data['links']['bucket'] | |
for filename in files: | |
print(filename) | |
with open(path / filename, 'rb') as fp: | |
response = requests.put('%s/%s' % (bucket_url, filename), data=fp, params=params) | |
response.raise_for_status() | |
print(response.status_code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment