diff --git a/initdb_from_csv.py b/initdb_from_csv.py index 7194a86..2f5396a 100755 --- a/initdb_from_csv.py +++ b/initdb_from_csv.py @@ -7,6 +7,13 @@ from optparse import OptionParser from hashlib import sha256 import os.path import sys +import string +import re + +# SIIUE names have alien strings like "(TE)" and are sometimes capitalized +def fixname(s): + return string.capwords(re.sub('\(.*\)', '', s).strip()) + # --------- Parse command line options ----------- parser = OptionParser('usage: %prog [options] inputfile.csv') @@ -67,7 +74,7 @@ with open(args[0], encoding='iso-8859-1') as csvfile: # SIIUE format next(csvreader) # ignore header c.executemany('INSERT INTO students VALUES (?,?,?)', - [(row[0], row[1], password) for row in csvreader]) + [(row[0], fixname(row[1]), password) for row in csvreader]) c.execute('INSERT INTO students VALUES ("0", "Professor", "")') conn.commit() # commit DB changes c.close() # close DB cursor -- libgit2 0.21.2