Commit 57a82bd19881728db249f8649ff1875b75a4240a
1 parent
ef03716c
Exists in
master
and in
1 other branch
- fix names from SIIUE in the script initdb_from_csv.py
Showing
1 changed file
with
8 additions
and
1 deletions
Show diff stats
initdb_from_csv.py
... | ... | @@ -7,6 +7,13 @@ from optparse import OptionParser |
7 | 7 | from hashlib import sha256 |
8 | 8 | import os.path |
9 | 9 | import sys |
10 | +import string | |
11 | +import re | |
12 | + | |
13 | +# SIIUE names have alien strings like "(TE)" and are sometimes capitalized | |
14 | +def fixname(s): | |
15 | + return string.capwords(re.sub('\(.*\)', '', s).strip()) | |
16 | + | |
10 | 17 | |
11 | 18 | # --------- Parse command line options ----------- |
12 | 19 | parser = OptionParser('usage: %prog [options] inputfile.csv') |
... | ... | @@ -67,7 +74,7 @@ with open(args[0], encoding='iso-8859-1') as csvfile: # SIIUE format |
67 | 74 | next(csvreader) # ignore header |
68 | 75 | |
69 | 76 | c.executemany('INSERT INTO students VALUES (?,?,?)', |
70 | - [(row[0], row[1], password) for row in csvreader]) | |
77 | + [(row[0], fixname(row[1]), password) for row in csvreader]) | |
71 | 78 | c.execute('INSERT INTO students VALUES ("0", "Professor", "")') |
72 | 79 | conn.commit() # commit DB changes |
73 | 80 | c.close() # close DB cursor | ... | ... |