-
-
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/
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
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