-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply substitutions from CSV file for 260c date field. Part of #94
- Loading branch information
Showing
4 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
import csv | ||
|
||
reader = csv.reader(sys.stdin, dialect='excel-tab') | ||
writer = csv.writer(sys.stdout, quoting=csv.QUOTE_ALL) | ||
|
||
for lineno, row in enumerate(reader): | ||
if lineno == 0: | ||
continue # skip header | ||
|
||
recid = row[0] | ||
orig260c = row[1] | ||
new260c_from = row[4] | ||
new260c_till = row[5] | ||
|
||
key = recid + "/" + orig260c | ||
val = new260c_from | ||
|
||
if new260c_till: | ||
val += "-" + new260c_till | ||
|
||
# skip trivial cases (already handled by conversion) | ||
if orig260c == val: | ||
continue | ||
|
||
if orig260c == val + ".": | ||
continue | ||
|
||
if orig260c == val + "-": | ||
continue | ||
|
||
if orig260c == val + "-.": | ||
continue | ||
|
||
if orig260c == "[" + val + "]": | ||
continue | ||
|
||
if orig260c == "[" + val + "].": | ||
continue | ||
|
||
|
||
writer.writerow([key, val]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Apply cleanup substitutions from CSV files to MARC records | ||
|
||
marc_map('001',recid) | ||
marc_map('260c',orig260c) | ||
if exists(orig260c) | ||
paste(substval,recid,orig260c,join_char:"/") | ||
lookup(substval,'refdata/subst-260c.csv',delete:1) | ||
if exists(substval) | ||
marc_set('260c',$.substval) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters