def contrib(r): contribs = [] for f in r.get_fields('700'): print f.subfield_sequence contrib = {} if 'a' not in f.contents and 'c' not in f.contents: continue # should at least be a name or title name = " ".join( [j.strip(' /,;:') for i, j in f.subfield_sequence if i in 'abc']) if 'd' in f.contents: contrib = pick_first_date(f.contents['d']) contrib['db_name'] = ' '.join([name] + f.contents['d']) else: contrib['db_name'] = name contrib['name'] = name contrib['entity_type'] = 'person' subfields = [('a', 'personal_name'), ('b', 'numeration'), ('c', 'title')] for subfield, field_name in subfields: if subfield in f.contents: contrib[field_name] = ' '.join( [x.strip(' /,;:') for x in f.contents[subfield]]) if 'q' in f.contents: contrib['fuller_name'] = ' '.join(f.contents['q']) contribs.append(contrib) for f in r.get_fields('710'): print f.subfield_sequence contrib = { 'entity_type': 'org', 'name': " ".join([ j.strip(' /,;:') for i, j in f.subfield_sequence if i in 'ab' ]) } contrib['db_name'] = contrib['name'] contribs.append(contrib) for f in r.get_fields('711'): print f.subfield_sequence contrib = { 'entity_type': 'event', 'name': " ".join([ j.strip(' /,;:') for i, j in f.subfield_sequence if i in 'acdn' ]) } contrib['db_name'] = contrib['name'] contribs.append(contrib) return contribs
def contrib(r): contribs = [] for f in r.get_fields('700'): print f.subfield_sequence contrib = {} if 'a' not in f.contents and 'c' not in f.contents: continue # should at least be a name or title name = " ".join([j.strip(' /,;:') for i, j in f.subfield_sequence if i in 'abc']) if 'd' in f.contents: contrib = pick_first_date(f.contents['d']) contrib['db_name'] = ' '.join([name] + f.contents['d']) else: contrib['db_name'] = name contrib['name'] = name contrib['entity_type'] = 'person' subfields = [ ('a', 'personal_name'), ('b', 'numeration'), ('c', 'title') ] for subfield, field_name in subfields: if subfield in f.contents: contrib[field_name] = ' '.join([x.strip(' /,;:') for x in f.contents[subfield]]) if 'q' in f.contents: contrib['fuller_name'] = ' '.join(f.contents['q']) contribs.append(contrib) for f in r.get_fields('710'): print f.subfield_sequence contrib = { 'entity_type': 'org', 'name': " ".join([j.strip(' /,;:') for i, j in f.subfield_sequence if i in 'ab']) } contrib['db_name'] = contrib['name'] contribs.append(contrib) for f in r.get_fields('711'): print f.subfield_sequence contrib = { 'entity_type': 'event', 'name': " ".join([j.strip(' /,;:') for i, j in f.subfield_sequence if i in 'acdn']) } contrib['db_name'] = contrib['name'] contribs.append(contrib) return contribs