Allow date option to be unspecified, fix 245$h handling
authorDan Scott <dan@coffeecode.net>
Tue, 7 Apr 2020 20:02:10 +0000 (16:02 -0400)
committerDan Scott <dan@coffeecode.net>
Tue, 7 Apr 2020 20:02:10 +0000 (16:02 -0400)
We had always been adding the last two characters of 245$h, even if they
were just "].", which messes up some records. Let's only add them if
they are " /".

Signed-off-by: Dan Scott <dan@coffeecode.net>
tools/ebooks/prep_ebook_records.py

index 339da4f..d04e650 100755 (executable)
@@ -286,7 +286,8 @@ def check_options(options):
     clean_opts["input"] = _input
     clean_opts["output"] = _output
     clean_opts["settings"] = Institution()
-    clean_opts["date"] = datetime.date.fromisoformat(clean_opts["date"])
+    if "date" in clean_opts:
+        clean_opts["date"] = datetime.date.fromisoformat(clean_opts["date"])
 
     return clean_opts
 
@@ -514,7 +515,7 @@ def process_record(record, options, files):
 
         date_cutoff = False
 
-        if options["date"]:
+        if "date" in options:
             u = record["856"]["u"]
             date_match = re.search(r"([\d]{4})-([\d]{2})-([\d]{2})", u)
 
@@ -607,7 +608,8 @@ def process_fields(record, options):
                 # Grab the trailing " /"
                 suffix = field["h"][-2:]
                 field.delete_subfield("h")
-                field["a"] = field["a"] + suffix
+                if suffix == " /":
+                    field["a"] = field["a"] + suffix
             new_record.add_ordered_field(field)
         else:
             new_record.add_ordered_field(field)