Skip to content

Commit 21c2a5a

Browse files
authored
split post newversion and put new metadata in update_and_release_to_zenodo.py
1 parent 370a308 commit 21c2a5a

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

scripts/update_and_release_to_zenodo.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,40 @@
1111

1212
def create_new_version():
1313
"""Creates a new version of the deposition and returns its ID."""
14+
# Create a new version
15+
response = requests.post(f"{ZENODO_API_BASE}/{DEPOSITION_ID}/actions/newversion", headers=HEADERS)
16+
17+
if response.status_code != 201:
18+
print(f"Error creating new version: {response.text}")
19+
sys.exit(1)
20+
21+
new_deposition = response.json()
22+
new_id = new_deposition["id"]
23+
print(f"New Zenodo deposition created: {new_id}")
24+
25+
# Get today's date for publication_date
1426
today_date = datetime.today().strftime('%Y-%m-%d')
15-
16-
# Retrieve the current metadata
17-
response = requests.get(f"{ZENODO_API_BASE}/{DEPOSITION_ID}", headers=HEADERS)
27+
28+
# Retrieve the current metadata and update publication_date
29+
response = requests.get(f"{ZENODO_API_BASE}/{new_id}", headers=HEADERS)
1830
if response.status_code != 200:
1931
print(f"Error retrieving deposition metadata: {response.text}")
2032
sys.exit(1)
2133

2234
deposition = response.json()
2335
metadata = deposition["metadata"]
24-
25-
# Add the publication_date if missing
2636
metadata["publication_date"] = today_date
2737

28-
# Create a new version with the updated metadata
38+
# Update the metadata using PUT
2939
data = {"metadata": metadata}
40+
response = requests.put(f"{ZENODO_API_BASE}/{new_id}", headers=HEADERS, json=data)
3041

31-
response = requests.post(f"{ZENODO_API_BASE}/{DEPOSITION_ID}/actions/newversion", headers=HEADERS, json=data)
32-
33-
if response.status_code != 201:
34-
print(f"Error creating new version: {response.text}")
42+
if response.status_code != 200:
43+
print(f"Error updating metadata: {response.text}")
3544
sys.exit(1)
3645

37-
new_deposition = response.json()
38-
new_id = new_deposition["id"]
39-
print(f"New Zenodo deposition created: {new_id}")
46+
print(f"Metadata updated for deposition {new_id}.")
47+
4048
return new_id
4149

4250
def delete_existing_files(deposition_id):

0 commit comments

Comments
 (0)