1111
1212def 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
5053def delete_existing_files (deposition_id ):
0 commit comments