-
Notifications
You must be signed in to change notification settings - Fork 0
/
oclc_glue_rmwg.py
27 lines (25 loc) · 1.11 KB
/
oclc_glue_rmwg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import pymarc
marcFileIn = pymarc.MARCReader(open('rec_merge_export.mrc', 'rb'))
with open('rec_merge_export_oclcglued.mrc', 'wb') as f:
for record in marcFileIn:
if record['035'] is not None:
for fd in record.get_fields('035'):
if fd['a'].startswith('(OCoLC)'):
oclcNum = ''.join(x for x in fd['a'] if x.isdigit())
newfield959 = pymarc.Field(
tag='959',
indicators=[' ', ' '],
subfields=['a', oclcNum]
)
record.add_ordered_field(newfield959)
if record['019'] is not None:
for fd019 in record.get_fields('019'):
fd019as = fd019.get_subfields('a')
for fd019a in fd019as:
newfield959 = pymarc.Field(
tag='959',
indicators=[' ', ' '],
subfields=['a', fd019a]
)
record.add_ordered_field(newfield959)
f.write(record.as_marc21())