Skip to content

Commit 9bf9788

Browse files
authored
Merge pull request #52 from saw-leipzig/develop
minor fixes
2 parents 24c7191 + 2f65309 commit 9bf9788

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

csv2cmi.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,23 +159,31 @@ def createFileDesc(config):
159159

160160
def createCorrespondent(nameString):
161161
if letter[nameString]:
162+
defaultElement = 'name'
162163
correspondents = []
164+
personIDs = []
163165
# Turning the cells of correspondent names and their IDs into lists since cells
164166
# can contain various correspondents split by an extra delimiter.
165167
# In that case it is essential to be able to call each by their index.
166168
if subdlm:
167169
persons = letter[nameString].split(subdlm)
168-
personIDs = letter[nameString + "ID"].split(subdlm)
170+
try:
171+
personIDs = letter[nameString + "ID"].split(subdlm)
172+
except KeyError:
173+
defaultElement = 'persName'
169174
else:
170-
persons = [letter[nameString].strip()]
171-
personIDs = [letter[nameString + "ID"]]
175+
persons = [letter[nameString]]
176+
try:
177+
personIDs = [letter[nameString + "ID"]]
178+
except KeyError:
179+
defaultElement = 'persName'
172180
for index, person in enumerate(persons):
181+
correspondent = Element(defaultElement)
173182
person = str(person).strip()
174-
correspondent = Element('name')
175183
# assigning authority file IDs to their correspondents if provided
176184
if (index < len(personIDs)) and personIDs[index]:
177185
# by default complete GND-IDNs to full URI
178-
if 'http://' not in str(personIDs[index].strip()) and str(personIDs[index])[:-2].isdigit():
186+
if 'http://' not in str(personIDs[index].strip()) and str(personIDs[index].strip())[:-2].isdigit():
179187
logging.debug('Assigning ID %s to GND', str(
180188
personIDs[index].strip()))
181189
authID = 'http://d-nb.info/gnd/' + \
@@ -563,7 +571,8 @@ def processPlace(letter, correspondent):
563571
bibl.text = editionTitle
564572
bibl.set('type', editionType)
565573
except configparser.NoOptionError:
566-
logging.warning('Incomplete section %s in ini file. Title and type option must be set.', editionKey)
574+
logging.warning(
575+
'Incomplete section %s in ini file. Title and type option must be set.', editionKey)
567576
except configparser.NoSectionError:
568577
# if there is no matching section, we assume that there should be no one
569578
pass

0 commit comments

Comments
 (0)