#!/usr/bin/env python
+"""
+Prepare sets of electronic resource MARC records for loading into Evergreen
-import codecs, os, os.path, sys, getopt, pymarc, pymarc.marc8
+To avoid duplicating MARC records in Conifer, to minimize manual labour,
+and to make records as consistent as possible, we want to automate the
+processing of electronic resource MARC records purchased by two or more
+Conifer institutions.
+
+Each institution must confirm the standard data they require to be added
+to e-book MARC records. The principle here is to identify standard
+requirements that would be the same for each record and therefore can
+be accommodated in batch load.
+"""
+
+import os, os.path, sys, getopt, pymarc, pymarc.marc8
class Institution():
"""Defines standard settings for each Conifer institution"""
"code": "OWA", \
"ebrary_code": "oculwindsor", \
"proxy": "http://ezproxy.uwindsor.ca/login?url=", \
- "public_note": "To view Windsor's electronic resource click here.", \
+ "public_note": "To view Windsor's electronic resource click here.",\
"link_text": "To view Windsor's electronic resource click here." \
}
_short_opts = 'i:o:p:ALWn:h'
_long_opts = ['input=', 'output=', 'publisher=', 'algoma', \
'laurentian', 'windsor', 'note=', 'help']
- opts, args = getopt.getopt(sys.argv[1:], _short_opts, _long_opts)
+ opts = getopt.getopt(sys.argv[1:], _short_opts, _long_opts)
except getopt.GetoptError, ex:
print "* %s" % str(ex)
do_help()
- _options = consolidate_options(opts)
+ _options = consolidate_options(opts[0])
return check_options(_options)
def process_records(options):
for record in reader:
url = False
cnt = cnt + 1
- if record['856'] and record['856']['u']:
- url_tag = record['856']['u']
- # print url
- else:
+ if not (record['856'] and record['856']['u']):
print("* No 856 for record # %s" % (cnt))
new_record = pymarc.Record()
if url == False:
url = True
new_fields = process_urls(field, options)
- for nf in new_fields:
- new_record.add_field(nf)
+ for new_856 in new_fields:
+ new_record.add_field(new_856)
else:
new_record.add_field(field)
seven_ten = pymarc.Field(tag = '710',
indicators = ['2', ' '],
subfields = [
- 'a', options['publisher']
+ 'a', options['publisher'] + '(Firm)'
]
)
new_record.add_field(seven_ten)
]
)
new_record.add_field(note)
-
+
+ forty = pymarc.Field(tag = '040',
+ indicators = [' ', ' '],
+ subfields = [ 'a', 'CaOWA' ]
+ )
+ new_record.add_field(forty)
+
writer.write(new_record)
def process_urls(field, options):
new_fields = []
- try:
- url = field['u']
- except Error:
+ if not field['u']:
print "* No subfield 'u' found in this 856"
return None
eight_five_six = pymarc.Field(tag = '856',
indicators = ['4', '0'],
subfields = [
- 'u', data['proxy'] + url,
+ 'u', data['proxy'] + field['u'],
'y', data['link_text'],
'z', data['public_note'],
'9', data['code']
if __name__ == '__main__':
- options = parse_opts()
- process_records(options);
-
-## Okay, made it through the basic invocation requirements; moving on
-#
-#For each MARC record:
-#
-#Find the 856 u ($url)
-#for each institution:
-#create a new 856 40
-#if $url =~ /\.ebrary\./, then:
-#$url =~ s/^.*?id=(\d+)\s*$/$1/
-#$url = http://site.ebrary.com/lib/ + institution.ebrary_code + "/Doc?id=" + $url
-#else:
-#$url = institution.proxy + $url
-#$u = $url
-#$y = institution.link_text
-#$z = institution.public_note
-#$9 = institution.code
+ process_records(parse_opts())