Skip to content

Commit

Permalink
Fix errors in script
Browse files Browse the repository at this point in the history
  • Loading branch information
michamos committed May 3, 2024
1 parent 71c6cf1 commit e3cd58b
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions scripts/nsr-add-id/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@


def get_unambiguous_ids(url):
"""Get a mapping from doi to NSR record ID, ignoring duplicate ambiguous DOIs."""
"""Get a mapping from doi to NSR record ID, ignoring duplicate DOIs."""
seen = set()
result = {}
data = requests.get(url).json()
for nsr_id, doi in data:
doi = doi.lower()
if doi in seen:
result.pop(doi, None)
seen.add(doi.lower())
seen.add(doi)
result[doi] = nsr_id
return result

Expand All @@ -33,20 +34,22 @@ class AddNSRIds(SearchCheckDo):

@staticmethod
def check(record, logger, state):
dois = record.set_value("dois.value", [])
return str(record["control_number"]) in NSR_IDS and not any(
id_["schema"] == "NSR"
for id_ in record.get("external_system_identifiers", [])
)
if any(id_["schema"] == "NSR" for id_ in record.get(ELEMENT, [])):
return False
for doi in record.get_value("dois.value", []):
if doi.lower() in NSR_IDS:
state[nsr_id] = NSR_IDS[doi.lower()]
return True
return False

@staticmethod
def do(record, logger, state):
record.setdefault(ELEMENT, []).append(
{
"value": NSR_IDS[str(record["control_number"])],
"value": NSR_IDS[state[nsr_id]],
"schema": "NSR",
}
)


AddMsnetIds()
AddNSRIds()

0 comments on commit e3cd58b

Please sign in to comment.