Commit 46e9fdef authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Functionality to update all DOI urls at datacite.

parent 9db663a2
...@@ -27,6 +27,22 @@ from nomad.datamodel import User ...@@ -27,6 +27,22 @@ from nomad.datamodel import User
from nomad import config, utils from nomad import config, utils
def edit_url(doi: str, url: str = None):
""" Changes the URL of an already findable DOI. """
if url is None:
url = 'https://repository.nomad-coe.eu/app/gui/datasets/doi/%s' % doi
metadata_url = '%s/doi/%s' % (config.datacite.mds_host, doi)
response = requests.put(
metadata_url,
headers={'Content-Type': 'text/plain;charset=UTF-8'},
data='doi=%s\nurl=%s' % (doi, url), **_requests_args())
if response.status_code >= 300:
raise Exception('Unexpected datacite response (status code %d): %s' % (
response.status_code, response.text))
def _xml(parent, element: str, value: str = None): def _xml(parent, element: str, value: str = None):
path = element.split('/') path = element.split('/')
el = parent el = parent
......
from nomad import doi, infrastructure, utils
from nomad.datamodel import Dataset
if __name__ == '__main__':
infrastructure.setup_logging()
infrastructure.setup_mongo()
for dataset in Dataset.m_def.m_x('me').objects(doi__exists=True):
try:
doi.edit_url(doi=dataset.doi)
except Exception as e:
utils.get_logger('__name__').error('could not rewrite doi', exc_info=e)
else:
print('Rewrote URL of %s' % dataset.doi)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment