From 57a82bd19881728db249f8649ff1875b75a4240a Mon Sep 17 00:00:00 2001 From: Miguel Barao Date: Mon, 22 Jun 2015 16:37:30 +0100 Subject: [PATCH] - fix names from SIIUE in the script initdb_from_csv.py --- initdb_from_csv.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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