From: Dan Scott Date: Tue, 17 Apr 2018 18:10:38 +0000 (-0400) Subject: Add a "cut-field" option to strip fields X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=2a3240f575307b85700b0d0998e64f230e04efd6;p=contrib%2FConifer.git Add a "cut-field" option to strip fields Note that this will strip all instances of the field from every record, so use with care. Signed-off-by: Dan Scott --- diff --git a/tools/ebooks/prep_ebook_records.py b/tools/ebooks/prep_ebook_records.py index 8b6d07da00..33dea86f0b 100755 --- a/tools/ebooks/prep_ebook_records.py +++ b/tools/ebooks/prep_ebook_records.py @@ -145,6 +145,8 @@ Optional arguments: -s / --sample : The name of the sample output MARC file (generates 1 sample record for every 100 records processed) + -x / --cut-field : Space-delimited field names to strip out of each record + -h / --help : Prints help message Examples: @@ -175,6 +177,7 @@ def consolidate_options(opts): '-B': '--boreal', '-L': '--laurentian', '-s': '--sample', + '-x': '--cut-field', '-h': '--help' } @@ -242,6 +245,7 @@ def check_options(options): '--note': 'note', '--platform': 'platform', '--sample': 'sample', + '--cut-field': 'cut-field', '--tcn': 'tcn', '--to-format': 'to-format', '--url': 'url', @@ -380,7 +384,7 @@ def parse_opts(): 'publisher=', 'platform=', 'algoma', 'boreal', 'laurentian', 'consortium=', 'ebrary', 'clean', 'isbn-sfx', 'duplicate=', 'from-format=', 'to-format=', 'tcn=', 'url=', 'note=', 'sample=', - 'help' + 'cut-field=', 'help' ] opts = getopt.getopt(sys.argv[1:], _short_opts, _long_opts) except getopt.GetoptError, ex: @@ -513,6 +517,9 @@ def process_fields(record, options): # Strip out 300 fields that only contain placeholders elif field.tag == '300' and field['a'] == 'p. cm.': pass + # Strip out useless fields + elif 'cut-field' in options and field.tag in options['cut-field']: + pass elif field.tag == '008' and field.value()[23] != 's': fixed_field = pymarc.Field( tag='008',