-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbmod.py
executable file
·52 lines (39 loc) · 1.2 KB
/
dbmod.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python2.6
import csv, cgi, cgitb
def recordGuess(item, guess):
""" Log a guess for an item in the database """
rows = []
offset = {
'horse': 1,
'weed': 2,
'mind': 3
}[guess]
with open('database.csv', 'r') as file:
read = csv.reader(file, delimiter=',', quoting=csv.QUOTE_NONE)
for row in read:
rows.append(row)
stat = 0
index = 0
if item in rows[0]:
stat = 0
index = rows[0].index(item)
elif item in rows[4]:
stat = 4
index = rows[4].index(item)
elif item in rows[8]:
stat = 8
index = rows[8].index(item)
else:
return #critical error
rows[stat + offset][index] = int(rows[stat + offset][index]) + 1
with open('database.csv', 'w') as file:
write = csv.writer(file, delimiter=',', quoting=csv.QUOTE_NONE)
write.writerows(rows)
cgitb.enable()
data = cgi.FieldStorage()
recordGuess(data.getvalue('horse'), 'horse')
recordGuess(data.getvalue('weed'), 'weed')
recordGuess(data.getvalue('mind'), 'mind')
print "Content-type: text/html"
print
print "Update OK"