def create_999_field(rec, oclc_nums): rec_003 = rec.get_fields('003')[0].value() rec_001 = rec.get_fields('001')[0].value() rec_999s = rec.get_fields('999') if len(rec_999s) == 0: new_999 = Field(tag='999', indicators=[' ',' '], subfields=['i',rec_001]) for oclc_num in oclc_nums: new_999.add_subfield('o',oclc_num) rec_orig.add_ordered_field(new_999) rec.add_ordered_field(new_999) msg += 'Record 999: '+new_999.value()+'\n' elif len(rec_999s) > 0: msg += 'ERROR-MISC: Record contains at least one 999 field\n' for rec_999 in rec_999s: msg += ' '+rec_999+'\n'
def create_999_field(rec, oclc_nums): rec_003 = rec.get_fields('003')[0].value() rec_001 = rec.get_fields('001')[0].value() rec_999s = rec.get_fields('999') if len(rec_999s) == 0: new_999 = Field(tag='999', indicators=[' ', ' '], subfields=['i', rec_001]) for oclc_num in oclc_nums: new_999.add_subfield('o', oclc_num) rec_orig.add_ordered_field(new_999) rec.add_ordered_field(new_999) msg += 'Record 999: ' + new_999.value() + '\n' elif len(rec_999s) > 0: msg += 'ERROR-MISC: Record contains at least one 999 field\n' for rec_999 in rec_999s: msg += ' ' + rec_999 + '\n'
def process_001_003_fields(rec_orig, rec, oclc_nums_bsns_all): msg = '' oclc_id = '' inst_id = '' oclc_match = False rec_003_value = rec.get_fields('003')[0].value() # the institutional code from the 003 (either "OCLC" or a partner institution) rec_001_value = rec.get_fields('001')[0].value() # the local record number from the 001 (either the OCLC number or the partner's BSN) # Process OCLC records exported from Connexion if rec_001_value.startswith('o'): oclc_id = '('+rec_003_value+')'+rec_001_value msg += 'OCLC ID: '+oclc_id+'\n' # for oclc records, add a new 999 $i subfield containing the orig record's 001/003 data using txt file # extract list of OCLC numbers for this OCLC record from 035 subfields $a and $z rec_oclc_nums = set() if len(rec.get_fields('035')) > 0: # check if there are any 035 fields in the OCLC record for rec_035 in rec.get_fields('035'): # iterate through each of the 035 fields rec_035az = rec_035.get_subfields('a','z') # capture all the subfields a or z in the 035 field if len(rec_035az) > 0: # check if any subfields a or z exist for this_az in rec_035az: # iterate through each of the subfields a or z this_oclc_num = strip_number(this_az) # strip the subfield data down to just the OCLC number digits rec_oclc_nums.add(this_oclc_num) # add the number to the list of this record's OCLC numbers msg += ' oclc_rec_035_num: '+str(this_az)+'\n' for line in oclc_nums_bsns_all: # iterate through each of the lines in the txt file containing 001s/003s and OCLC numbers from original records if line.startswith('003'): # this is the first header line in the txt file # skip the header row skipped_line = line else: # process the line data from the oclc_nums_bsns_all txt file line_data = line.split(',') line_003 = line_data[0].strip() # capture the partner's institution code line_001 = line_data[1].strip() # capture the partner's bsn line_oclc_nums = line_data[2].strip() # capture the corresponding OCLC numbers and remove any white space around them line_oclc_nums = line_oclc_nums.strip('"') # remove the quotes around the OCLC number(s) line_oclc_nums = line_oclc_nums.split('|') # create a list of the OCLC numbers based on the pipe delimiter, in case there are more than one # iterate through this record's OCLC numbers to see if one is in the list of all OCLC numbers for this batch for rec_oclc_num in rec_oclc_nums: for line_oclc_num in line_oclc_nums: if line_oclc_num == rec_oclc_num: oclc_match = True inst_id = line_003+'_'+line_001 msg += 'Institution ID: '+inst_id+'\n' # delete the existing 001/003 fields from the OCLC record containing the OCLC number and symbol rec.remove_field(rec.get_fields('003')[0]) rec.remove_field(rec.get_fields('001')[0]) # add new 001/003 fields to the OCLC record containing the partner's bsn and institution code new_003 = Field(tag='003', data=line_003) rec.add_ordered_field(new_003) new_001 = Field(tag='001', data=line_001) rec.add_ordered_field(new_001) if not oclc_match: msg += 'ERROR-MISC: OCLC numbers in this OCLC record did not match any original record\n' # Process Original Records (no OCLC record found in Connexion) else: inst_id = rec_003_value+'_'+rec_001_value msg += 'Institution ID: '+inst_id+'\n' # for orig records, delete all existing 035 fields if len(rec.get_fields('035')) > 0: for rec_035 in rec.get_fields('035'): msg += ' orig_rec_035 num: '+str(rec_035)+'\n' rec.remove_field(rec_035) # delete this 035 field rec_999s = rec.get_fields('999') if len(rec_999s) == 0: if oclc_id == '': new_999_nums = Field(tag='999', indicators=[' ',' '], subfields=['i',inst_id]) else: new_999_nums = Field(tag='999', indicators=[' ',' '], subfields=['i',inst_id,'o',oclc_id]) rec_orig.add_ordered_field(new_999_nums) rec.add_ordered_field(new_999_nums) msg += 'Record 999: '+new_999_nums.value()+'\n' elif len(rec_999s) > 1: msg += 'ERROR-MISC: Record contains multiple 999 fields\n' for rec_999 in rec_999s: msg += ' '+rec_999+'\n' elif len(rec_999s) == 1: new_999 = deepcopy(rec_999s[0]) for new_999e in new_999.get_subfields('e'): # delete any existing subfield $e in the new 999 field new_999.delete_subfield('e') msg += 'Record 999: '+new_999.value()+'\n' return (rec_orig, rec, oclc_id, inst_id, oclc_match, msg)
def bib_patches(system, library, agent, vendor, bib): """ Treatment of specific records; special cases """ # nypl remove OCLC prefix & add appropriate 910 tag if system == "nypl": if "001" in bib: controlNo = bib.get_fields("001")[0].data changed, controlNo = remove_oclc_prefix(controlNo) if changed: bib.remove_fields("001") field = Field(tag="001", data=controlNo) bib.add_ordered_field(field) bib.remove_fields("910") tag_910 = create_tag_910(system, library) bib.add_ordered_field(tag_910) # nypl branches cat patch for BT Series if ( system == "nypl" and library == "branches" and agent == "cat" and vendor == "BT SERIES" ): # parse the call number new_callno = [] pos = 0 if "091" in bib: callno = bib.get_fields("091")[0].value() # langugage and audience prefix if callno[:6] == "J SPA ": new_callno.extend(["p", "J SPA"]) elif callno[:2] == "J ": new_callno.extend(["p", "J"]) # format prefix if "GRAPHIC " in callno: new_callno.extend(["f", "GRAPHIC"]) elif "HOLIDAY " in callno: new_callno.extend(["f", "HOLIDAY"]) elif "YR " in callno: new_callno.extend(["f", "YR"]) # main subfield if "GN FIC " in callno: pos = callno.index("GN FIC ") + 7 new_callno.extend(["a", "GN FIC"]) elif "FIC " in callno: pos = callno.index("FIC ") + 4 new_callno.extend(["a", "FIC"]) elif "PIC " in callno: pos = callno.index("PIC ") + 4 new_callno.extend(["a", "PIC"]) elif callno[:4] == "J E ": pos = callno.index("J E ") + 4 new_callno.extend(["a", "E"]) elif callno[:8] == "J SPA E ": pos = callno.index("J SPA E ") + 8 new_callno.extend(["a", "E"]) # cutter subfield new_callno.extend(["c", callno[pos:]]) field = Field(tag="091", indicators=[" ", " "], subfields=new_callno) # verify nothing has been lost if callno != field.value(): raise AssertionError( "Constructed call # does not match original." "New={}, original={}".format(callno, field.value()) ) else: # if correct remove the original and replace with new bib.remove_fields("091") bib.add_ordered_field(field) return bib