Skip to content

Commit

Permalink
Allow trailing blank lines in textid files
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Schmidt committed Aug 19, 2015
1 parent 23d2c80 commit 4450a57
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 9 additions & 3 deletions bookwormDB/CreateDatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ def text_id_dbm():
"""
dbm = anydbm.open(".bookworm/texts/textids.dbm","c")
for file in os.listdir(".bookworm/texts/textids"):
for line in open(".bookworm/texts/textids/" + file):
for line in open(".bookworm/texts/textids/" + file):
line = line.rstrip("\n")
splat = line.split("\t")
dbm[splat[1]] = splat[0]

try:
dbm[splat[1]] = splat[0]
except IndexError:
if line=="":
# It's OK to have a blank line, let's say.
continue
else:
raise
class DB:
def __init__(self,dbname=None):
config = ConfigParser.ConfigParser(allow_no_value=True)
Expand Down
8 changes: 6 additions & 2 deletions bookwormDB/variableSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ def __init__(self):
for filelist in filelists:
for line in open(".bookworm/texts/textids/%s" % filelist):
parts = line.replace('\n', '').split("\t")
self[parts[1]] = int(parts[0])
numbers.append(int(parts[0]))
if len(parts)==2:
# Allowing terminal newline.
self[parts[1]] = int(parts[0])
numbers.append(int(parts[0]))


self.new = open('.bookworm/texts/textids/new', 'a')
self.max = max(numbers)

Expand Down

0 comments on commit 4450a57

Please sign in to comment.