Skip to content

Instantly share code, notes, and snippets.

@lawlesst
Created October 29, 2010 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lawlesst/652661 to your computer and use it in GitHub Desktop.
Save lawlesst/652661 to your computer and use it in GitHub Desktop.
Couple of functions for handling linked marc fields in iii xrecord format.
#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