Add a "cut-field" option to strip fields
authorDan Scott <dscott@laurentian.ca>
Tue, 17 Apr 2018 18:10:38 +0000 (14:10 -0400)
committerDan Scott <dscott@laurentian.ca>
Tue, 17 Apr 2018 18:10:38 +0000 (14:10 -0400)
Note that this will strip all instances of the field from every
record, so use with care.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
tools/ebooks/prep_ebook_records.py

index 8b6d07d..33dea86 100755 (executable)
@@ -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',