Skip to content

Instantly share code, notes, and snippets.

@Pouyar69
Forked from slint/zenodo-upload.py
Last active April 25, 2023 12:16
Show Gist options
  • Save Pouyar69/696556ab7d24280885fc3a046b6ab58b to your computer and use it in GitHub Desktop.
Save Pouyar69/696556ab7d24280885fc3a046b6ab58b to your computer and use it in GitHub Desktop.
edited version of zenodo-upload.py which has a progress bar. thanks to https://loganbvh.github.io/
import os
import requests
from tqdm import tqdm # pip install tqdm
from tqdm.utils import CallbackIOWrapper
params = {'access_token': '<your-access-token>'}
# Create the deposit resource
url = "https://zenodo.org/api/deposit/depositions/<your-deposit-id>"
headers = {"Content-Type": "application/json"}
res = requests.get(
url,
json={},
params=params,
)
print(res.json())
bucket_url = res.json()["links"]["bucket"]
# Upload file
file_path = "<path-to-file-to-upload>"
file_size = os.stat(file_path).st_size
with open(file_path, "rb") as f:
with tqdm(total=file_size, unit="B", unit_scale=True, unit_divisor=1024) as t:
wrapped_file = CallbackIOWrapper(t.update, f, "read")
requests.put(
bucket_url + "/" + os.path.basename(file_path),
data=wrapped_file,
params=params,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment