Last active
August 29, 2015 14:27
-
-
Save miku/68c440af1f377025e319 to your computer and use it in GitHub Desktop.
Newline MARC
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
#!/usr/bin/env python | |
# coding: utf-8 | |
import pymarc | |
import string | |
record = pymarc.Record() | |
record.add_field( | |
pymarc.Field( | |
tag = '245', | |
indicators = ['0','1'], | |
subfields = [ | |
'a', 'The pragmatic\nprogrammer : ', | |
'b', 'from journeyman\nto master /', | |
'c', 'Andrew Hunt, David\nThomas.' | |
])) | |
# create a "broken" version | |
with open("with.mrc", "w") as handle: | |
w = pymarc.MARCWriter(handle) | |
w.write(record) | |
# all possible subfield codes? | |
codes = [str(i) for i in range(10)] + [s for s in string.lowercase] | |
for field in record.fields: | |
for c in codes: | |
if not c in field: | |
continue | |
field[c] = field[c].replace("\n", "") | |
# create a "cleaned" version | |
with open("without.mrc", "w") as handle: | |
w = pymarc.MARCWriter(handle) | |
w.write(record) |
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
all: | |
python fabricate.py | |
clean: | |
rm -f with.mrc | |
rm -f without.mrc |
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
00127 2200037 4500 | |
245 01 $a The pragmatic | |
programmer : $b from journeyman | |
to master / $c Andrew Hunt, David | |
Thomas. | |
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
00124 2200037 4500 | |
245 01 $a The pragmaticprogrammer : $b from journeymanto master / $c Andrew Hunt, DavidThomas. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment