Skip to content

Instantly share code, notes, and snippets.

@jalavik
Last active August 29, 2015 14:04
Show Gist options
  • Save jalavik/40012deb4fadd3c2a402 to your computer and use it in GitHub Desktop.
Save jalavik/40012deb4fadd3c2a402 to your computer and use it in GitHub Desktop.
How to match incoming records on recid in 035
def attempt_record_match(recid):
""" Tries to find out if the record is already in Inspire """
return perform_request_search(p="035:CDS and 035:%s" % (recid,), of="id")
for record in records:
# Step 1: Attempt to match the record to those already in Inspire
try:
recid = record['001'][0][3]
res = attempt_record_match(recid)
except (KeyError, IndexError) as err:
print('Error: Cannot process record without 001:recid')
error_records.append(record)
continue
if skip_recid_check or not res:
print("Record %s does not exist: inserting" % (recid,))
# Step 2: Appply filter to transform CDS MARC to Inspire MARC
insert_records.append(apply_filter(record))
else:
print("Record %s found: %r" % (recid, res))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment