From 9690f3a751bb7527368b27140fd8661af5960934 Mon Sep 17 00:00:00 2001 From: dbs Date: Wed, 24 Nov 2010 22:44:12 +0000 Subject: [PATCH] Significant clean up of the ebook prep script Refine some of Windsor's requirements, and handle some of the conditions raised by pylint to make things a tiny bit cleaner. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/conifer/branches/rel_1_6_1@1085 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- tools/ebooks/prep_ebook_records.py | 66 ++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/tools/ebooks/prep_ebook_records.py b/tools/ebooks/prep_ebook_records.py index 6e17dfaeb7..5fe7c1b846 100644 --- a/tools/ebooks/prep_ebook_records.py +++ b/tools/ebooks/prep_ebook_records.py @@ -1,6 +1,19 @@ #!/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""" @@ -27,7 +40,7 @@ class 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." \ } @@ -182,12 +195,12 @@ def parse_opts(): _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): @@ -200,10 +213,7 @@ 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() @@ -213,15 +223,15 @@ def process_records(options): 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) @@ -234,7 +244,13 @@ def process_records(options): ] ) 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): @@ -242,9 +258,7 @@ 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 @@ -253,7 +267,7 @@ def process_urls(field, options): 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'] @@ -265,22 +279,4 @@ def process_urls(field, options): 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()) -- 2.11.0