Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
milesstoetzner committed Nov 18, 2023
1 parent 6e27613 commit 8d15bc6
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions cmds/zenodo/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import datetime
import os

access_token = os.getenv('ZENODO_ACCESS_TOKEN')
original_id = int(os.getenv('ZENODO_ORIGINAL_ID'))
zenodo_url = os.getenv('ZENODO_URL', 'https://zenodo.org')
access_token = os.getenv('ZENODO_ACCESS_TOKEN', 'H5asXH8F3sfBfx3JxbrO0MsWLbpLHi2Rxt4QwfVJZXTQoHG3a2AgYoTQztS7')
original_id = int(os.getenv('ZENODO_ORIGINAL_ID', '91'))
zenodo_url = os.getenv('ZENODO_URL', 'https://sandbox.zenodo.org')
zenodo_files = '/tmp/opentosca-vintner-zenodo-files'
vintner_version = os.getenv('VINTNER_VERSION')
vintner_version = os.getenv('VINTNER_VERSION', 'asdfasdf')

if access_token is None:
raise Exception('ZENODO_ACCESS_TOKEN not defined')
Expand All @@ -17,17 +17,23 @@


def create_version(id):
print('Creating a new version')
r = requests.post(zenodo_url + '/api/deposit/depositions/' + str(id) + '/actions/newversion', params={'access_token': access_token})
print(r.status_code)
print(r.json())

print('Version created')
data = r.json()

# Delete all existing files
if 'files' in data:
print('Deleting existing files')
for file in data['files']:
print('Deleting file ' + file['filename'])
r = requests.delete(file['links']['self'], params={'access_token': access_token})
print(r.status_code)
print(r.json())
print(r.content)
print('File deleted')

# Set new publish date
set_metadata(data['id'])
Expand All @@ -36,12 +42,15 @@ def create_version(id):


def publish_version(id):
print('Publishing version ' + str(id))
r = requests.post(zenodo_url + '/api/deposit/depositions/' + str(id) + '/actions/publish', params={'access_token': access_token})
print(r.status_code)
print(r.json())
print('Version published')


def set_metadata(id):
print('Setting metadata')
data = {"metadata": {
"title": "OpenTOSCA Vintner",
"publication_date": current_date(),
Expand All @@ -67,27 +76,33 @@ def set_metadata(id):
r = requests.put(zenodo_url + '/api/deposit/depositions/' + str(id), data=json.dumps(data), headers=headers, params={'access_token': access_token})
print(r.status_code)
print(r.json())
print('Metadata set')


def upload_files(id):
print('Uploading files')
files = [file for file in os.listdir(zenodo_files) if os.path.isfile(os.path.join(zenodo_files, file))]
for file in files:
upload_file(id, file)
print('Files uploaded')


def upload_file(id, file):
print('Uploading file ' + file)
url = zenodo_url + '/api/deposit/depositions/' + str(id) + '/files'
data = {'name': file}
files = {'file': open(os.path.join(zenodo_files, file), 'rb')}
r = requests.post(url, params={'access_token': access_token}, data=data, files=files)
print(r.status_code)
print(r.json())

print('File uploaded')

def current_date():
return datetime.datetime.now().isoformat()[0:10]


print('Publishing new Zenodo release')
version_id = create_version(original_id)
upload_files(version_id)
publish_version(version_id)
print('Zenodo relase published')

0 comments on commit 8d15bc6

Please sign in to comment.