from datetime import date
from BeautifulSoup import BeautifulSoup
+RECORD_COUNT = 0
+
class Institution():
"""Defines standard settings for each Conifer institution"""
def process_records(options):
"""Converts raw ebook MARC records to Conifer-ready MARC records"""
+ global RECORD_COUNT
sample = ''
reader = pymarc.MARCReader(
open(options['input'], mode='rb'), to_unicode=True
if ('sample' in options):
sample = pymarc.MARCWriter(open(options['sample'], mode='wb'))
- cnt = 0
for record in reader:
- cnt = cnt + 1
+ RECORD_COUNT += 1
try:
if not (record['856'] and record['856']['u']):
- print("* No 856 for record # %s in file %s"
- % (cnt, options['input'])
+ print("* No 856 for record # %d in file %s"
+ % (RECORD_COUNT, options['input'])
)
new_record = process_fields(record, options)
writer.write(new_record)
- if (sample and ((cnt == 1) or (cnt % 100 == 0))):
+ if (sample and ((RECORD_COUNT == 1) or (RECORD_COUNT % 100 == 0))):
sample.write(new_record)
except Exception, ex:
- print("* Error processing record %s - %s" % (cnt, ex))
+ print("* Error processing record %d - %s" % (RECORD_COUNT, ex))
def process_fields(record, options):
"""Decide which fields to add, delete, and keep"""
* $9 - Institutional code to which this note applies
"""
+ # Add a period if the authorization ends with a number or letter
+ authnote = options['authorization']
+ if re.match(r'[a-zA-Z0-9]', authnote[-1]):
+ authnote += '.'
+
for library in options['libraries']:
libopts = options['settings'].get_settings(library)
# Add the access restriction note
subfields = [
'a', libopts['access_note'],
'b', options['consortium'] + ' ; ',
- 'e', options['authorization'] + '.',
+ 'e', authnote,
'9', libopts['code']
]
)
Add a 598 field identifying the source MARC file name and processing date
"""
+ global RECORD_COUNT
+
source = os.path.basename(options['input'])
marc_source = pymarc.Field(tag = '598',
indicators = [' ', ' '],
subfields = [
'a', source,
- 'b', date.today().isoformat()
+ 'b', date.today().isoformat(),
+ 'c', str(RECORD_COUNT)
]
)
record.add_field(marc_source)