Skip to content

Commit 220e920

Browse files
committed
Add identifier deletion script
1 parent 5a09510 commit 220e920

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

ames/matchers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .eprints import update_pub_data
1616
from .caltechauthors import add_journal_metadata
1717
from .caltechauthors import edit_author_identifier
18+
from .caltechauthors import delete_author_identifier
1819
from .caltechauthors import add_group
1920
from .caltechauthors import check_doi
2021
from .caltechauthors import add_doi

ames/matchers/caltechauthors.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,45 @@ def edit_author_identifier(
233233
)
234234

235235

236+
def delete_author_identifier(record, token, identifier_to_delete, test=False):
237+
# For a given record, delete a person identifier
238+
239+
if test:
240+
rurl = "https://authors.caltechlibrary.dev/api/records/" + record
241+
else:
242+
rurl = "https://authors.library.caltech.edu/api/records/" + record
243+
244+
headers = {
245+
"Authorization": "Bearer %s" % token,
246+
"Content-type": "application/json",
247+
}
248+
249+
data = requests.get(rurl, headers=headers).json()
250+
251+
update = False
252+
for creator in data["metadata"]["creators"]:
253+
block = creator["person_or_org"]
254+
if "identifiers" in block:
255+
new_identifiers = []
256+
for idv in block["identifiers"]:
257+
if idv["identifier"] != identifier_to_delete:
258+
new_identifiers.append(idv)
259+
else:
260+
update = True
261+
block["identifiers"] = new_identifiers
262+
263+
if update == True:
264+
print(record)
265+
caltechdata_edit(
266+
record,
267+
metadata=data,
268+
token=token,
269+
production=True,
270+
publish=True,
271+
authors=True,
272+
)
273+
274+
236275
def add_group(record, token, group_identifier, test=False):
237276
# For a given record, add a Caltech group identifier
238277

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import os, sys, argparse
2+
from ames.harvesters import get_author_records
3+
from ames.matchers import delete_author_identifier
4+
5+
token = os.environ["CTATOK"]
6+
7+
parser = argparse.ArgumentParser(
8+
prog="authors_name_update",
9+
description="Updates a name identifier or adds a new one",
10+
)
11+
12+
parser.add_argument(
13+
"search_identifier", type=str, help="The identifier to search by"
14+
)
15+
parser.add_argument("identifier_to_delete", type=str, help="The identifier to delete")
16+
17+
args = parser.parse_args()
18+
search_identifier = args.search_identifier
19+
identifier_to_delete = args.identifier_to_delete
20+
21+
to_update = get_author_records(search_identifier, token)
22+
for record in to_update:
23+
print(
24+
f"Deleting identifier {identifier_to_delete} from {record}"
25+
)
26+
delete_author_identifier(
27+
record,
28+
token,
29+
identifier_to_delete,
30+
)

0 commit comments

Comments
 (0)