Skip to content

Commit b8cf3bb

Browse files
authored
Update update_and_release_to_zenodo.py
from https://developers.zenodo.org/?python#quickstart-upload
1 parent 21c2a5a commit b8cf3bb

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

scripts/update_and_release_to_zenodo.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
def create_new_version():
1313
"""Creates a new version of the deposition and returns its ID."""
14-
# Create a new version
14+
# Step 1: Create a new version of the deposition
1515
response = requests.post(f"{ZENODO_API_BASE}/{DEPOSITION_ID}/actions/newversion", headers=HEADERS)
1616

1717
if response.status_code != 201:
@@ -22,20 +22,23 @@ def create_new_version():
2222
new_id = new_deposition["id"]
2323
print(f"New Zenodo deposition created: {new_id}")
2424

25-
# Get today's date for publication_date
25+
# Step 2: Update the metadata for the new version
2626
today_date = datetime.today().strftime('%Y-%m-%d')
2727

28-
# Retrieve the current metadata and update publication_date
28+
# Retrieve current metadata to update
2929
response = requests.get(f"{ZENODO_API_BASE}/{new_id}", headers=HEADERS)
3030
if response.status_code != 200:
3131
print(f"Error retrieving deposition metadata: {response.text}")
3232
sys.exit(1)
3333

3434
deposition = response.json()
3535
metadata = deposition["metadata"]
36+
37+
# Add dates and publication_date for the draft version
38+
metadata["dates"] = [{"date": today_date, "type": "published"}]
3639
metadata["publication_date"] = today_date
3740

38-
# Update the metadata using PUT
41+
# Update the metadata using PUT request
3942
data = {"metadata": metadata}
4043
response = requests.put(f"{ZENODO_API_BASE}/{new_id}", headers=HEADERS, json=data)
4144

@@ -44,7 +47,7 @@ def create_new_version():
4447
sys.exit(1)
4548

4649
print(f"Metadata updated for deposition {new_id}.")
47-
50+
4851
return new_id
4952

5053
def delete_existing_files(deposition_id):

0 commit comments

Comments
 (0)