|
11 | 11 |
|
12 | 12 | def create_new_version(): |
13 | 13 | """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 |
14 | 26 | 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) |
18 | 30 | if response.status_code != 200: |
19 | 31 | print(f"Error retrieving deposition metadata: {response.text}") |
20 | 32 | sys.exit(1) |
21 | 33 |
|
22 | 34 | deposition = response.json() |
23 | 35 | metadata = deposition["metadata"] |
24 | | - |
25 | | - # Add the publication_date if missing |
26 | 36 | metadata["publication_date"] = today_date |
27 | 37 |
|
28 | | - # Create a new version with the updated metadata |
| 38 | + # Update the metadata using PUT |
29 | 39 | data = {"metadata": metadata} |
| 40 | + response = requests.put(f"{ZENODO_API_BASE}/{new_id}", headers=HEADERS, json=data) |
30 | 41 |
|
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}") |
35 | 44 | sys.exit(1) |
36 | 45 |
|
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 | + |
40 | 48 | return new_id |
41 | 49 |
|
42 | 50 | def delete_existing_files(deposition_id): |
|
0 commit comments