diff --git a/ames/matchers/__init__.py b/ames/matchers/__init__.py index fb94431..223962e 100644 --- a/ames/matchers/__init__.py +++ b/ames/matchers/__init__.py @@ -18,3 +18,4 @@ from .caltechauthors import add_group from .caltechauthors import check_doi from .caltechauthors import add_doi +from .caltechauthors import move_doi diff --git a/ames/matchers/caltechauthors.py b/ames/matchers/caltechauthors.py index 919b0f7..578e785 100644 --- a/ames/matchers/caltechauthors.py +++ b/ames/matchers/caltechauthors.py @@ -210,3 +210,47 @@ def add_doi(record, token, test=False): publish=True, authors=True, ) + + +def move_doi(record, token, test=False): + # Move DOI from alternative identifier to DOI field + + if test: + rurl = "https://authors.caltechlibrary.dev/api/records/" + record + else: + rurl = "https://authors.library.caltech.edu/api/records/" + record + + headers = { + "Authorization": "Bearer %s" % token, + "Content-type": "application/json", + } + + data = requests.get(rurl, headers=headers).json() + + doi = None + identifiers = [] + + if "identifiers" in data["metadata"]: + for idv in data["metadata"]["identifiers"]: + if idv["scheme"] == "doi": + doi = idv["identifier"] + else: + identifiers.append(idv) + + if doi == None: + print(f"No DOI found for {record}") + exit() + else: + data["pids"]["doi"] = { + "provider": "external", + "identifier": doi, + } + data["metadata"]["identifiers"] = identifiers + caltechdata_edit( + record, + metadata=data, + token=token, + production=not test, + publish=True, + authors=True, + )