Skip to content

Commit

Permalink
Add move doi function
Browse files Browse the repository at this point in the history
  • Loading branch information
tmorrell committed Aug 9, 2024
1 parent ab21c42 commit f6167fc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions ames/matchers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
from .caltechauthors import add_group
from .caltechauthors import check_doi
from .caltechauthors import add_doi
from .caltechauthors import move_doi
44 changes: 44 additions & 0 deletions ames/matchers/caltechauthors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

0 comments on commit f6167fc

Please sign in to comment.