Skip to content

Instantly share code, notes, and snippets.

@miku
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miku/68c440af1f377025e319 to your computer and use it in GitHub Desktop.
Save miku/68c440af1f377025e319 to your computer and use it in GitHub Desktop.
Newline MARC
#!/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)
all:
python fabricate.py
clean:
rm -f with.mrc
rm -f without.mrc
00127 2200037 4500
245 01 $a The pragmatic
programmer : $b from journeyman
to master / $c Andrew Hunt, David
Thomas.
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