From 2f78b06c4589b3d486fa6ee96bf1d8236129e615 Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Tue, 7 Apr 2020 16:02:10 -0400 Subject: [PATCH] Allow date option to be unspecified, fix 245$h handling 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 --- tools/ebooks/prep_ebook_records.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/ebooks/prep_ebook_records.py b/tools/ebooks/prep_ebook_records.py index 339da4faa4..d04e650bba 100755 --- a/tools/ebooks/prep_ebook_records.py +++ b/tools/ebooks/prep_ebook_records.py @@ -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) -- 2.11.0