diff --git a/csv2cmi.py b/csv2cmi.py index 294bc06..fb18c51 100755 --- a/csv2cmi.py +++ b/csv2cmi.py @@ -159,23 +159,31 @@ def createFileDesc(config): def createCorrespondent(nameString): if letter[nameString]: + defaultElement = 'name' correspondents = [] + personIDs = [] # Turning the cells of correspondent names and their IDs into lists since cells # can contain various correspondents split by an extra delimiter. # In that case it is essential to be able to call each by their index. if subdlm: persons = letter[nameString].split(subdlm) - personIDs = letter[nameString + "ID"].split(subdlm) + try: + personIDs = letter[nameString + "ID"].split(subdlm) + except KeyError: + defaultElement = 'persName' else: - persons = [letter[nameString].strip()] - personIDs = [letter[nameString + "ID"]] + persons = [letter[nameString]] + try: + personIDs = [letter[nameString + "ID"]] + except KeyError: + defaultElement = 'persName' for index, person in enumerate(persons): + correspondent = Element(defaultElement) person = str(person).strip() - correspondent = Element('name') # assigning authority file IDs to their correspondents if provided if (index < len(personIDs)) and personIDs[index]: # by default complete GND-IDNs to full URI - if 'http://' not in str(personIDs[index].strip()) and str(personIDs[index])[:-2].isdigit(): + if 'http://' not in str(personIDs[index].strip()) and str(personIDs[index].strip())[:-2].isdigit(): logging.debug('Assigning ID %s to GND', str( personIDs[index].strip())) authID = 'http://d-nb.info/gnd/' + \ @@ -563,7 +571,8 @@ def processPlace(letter, correspondent): bibl.text = editionTitle bibl.set('type', editionType) except configparser.NoOptionError: - logging.warning('Incomplete section %s in ini file. Title and type option must be set.', editionKey) + logging.warning( + 'Incomplete section %s in ini file. Title and type option must be set.', editionKey) except configparser.NoSectionError: # if there is no matching section, we assume that there should be no one pass