Created
October 29, 2010 00:47
Couple of functions for handling linked marc fields in iii xrecord format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pass in elementree tree obj | |
#pass call linked_value('245', subfields=['a', 'c']) | |
def linked_fields(self): | |
linked_fields = [] | |
for field in self.var_fields: | |
rec_tag = field.findtext('MARCINFO/MARCTAG') | |
if '880' == rec_tag: | |
linked_fields.append((field.findall('MARCSUBFLD'), field)) | |
return linked_fields | |
def linked_value(self, tag, subfields=None): | |
return_text = [] | |
for info in self.lf(): | |
field_data = info[1] | |
indicators = info[0] | |
for indicator in indicators: | |
if indicator.find('SUBFIELDINDICATOR').text == '6': | |
if indicator.find('SUBFIELDDATA').text.split('-')[0] == tag: | |
#get the subfields for this 880 tag | |
these_subfields = field_data.findall('MARCSUBFLD') | |
#iterate through the sfs | |
for tag_cells in these_subfields: | |
sf_tag = tag_cells.find('SUBFIELDINDICATOR').text | |
sf_text = tag_cells.find('SUBFIELDDATA').text | |
if sf_tag in subfields: | |
return_text.append(normalize(sf_text)) | |
return ' '.join(return_text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment