From: Dan Scott Date: Fri, 1 Sep 2017 20:09:51 +0000 (-0400) Subject: Clean up ISBN fields while we're processing X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=86c397166c51197b3321d82d96758f55843aa358;p=contrib%2FConifer.git Clean up ISBN fields while we're processing Might as well put junk into 020q if we have it. Signed-off-by: Dan Scott --- diff --git a/tools/ebooks/prep_ebook_records.py b/tools/ebooks/prep_ebook_records.py index 063c2a2fcf..9a9dc5c1a2 100755 --- a/tools/ebooks/prep_ebook_records.py +++ b/tools/ebooks/prep_ebook_records.py @@ -506,6 +506,10 @@ def process_fields(record, options): # except for 924 fields that we create elif field.tag[0] == '9' and field.tag != '924': pass + # ISBN cleanup + elif field.tag == '020': + new_isbn = create_clean_isbn(field) + new_record.add_ordered_field(new_isbn) # Strip out 300 fields that only contain placeholders elif field.tag == '300' and field['a'] == 'p. cm.': pass @@ -945,6 +949,26 @@ def add_marc_source(record, options): ) record.add_ordered_field(marc_source) +def create_clean_isbn(field): + """Move 020a junk to 020q""" + + if not field.get_subfields('a') or ' ' not in field['a']: + return field + + isbn = pymarc.Field( + tag = '020', + indicators=[field.indicator1, field.indicator2] + ) + for sf in field: + if sf[0] == 'a' and ' ' in sf[1]: + junk = sf[1].strip() + junk = junk[junk.find(' '):].strip() + isbn.add_subfield('a', clean_isbn(sf[1])) + isbn.add_subfield('q', junk) + else: + isbn.add_subfield(sf[0], sf[1]) + return isbn + def process_urls(field, options, publisher): """Creates 856 fields required by Conifer"""