Skip to content

Instantly share code, notes, and snippets.

@jochenklar
Created June 28, 2021 18:31
Show Gist options
  • Save jochenklar/6acfb42a1931aa907cd846e063bd2b73 to your computer and use it in GitHub Desktop.
Save jochenklar/6acfb42a1931aa907cd846e063bd2b73 to your computer and use it in GitHub Desktop.
Upload script for zenodo
#!/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