-
Notifications
You must be signed in to change notification settings - Fork 0
/
Admin.py
36 lines (34 loc) · 917 Bytes
/
Admin.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
import pymysql as pm
import csv
def read_csv(filename):
file = open(filename);
csvreader = csv.reader(file);
header = next(csvreader);
print(header)
rows = []
for row in csvreader:
rows.append(row)
file.close()
return rows
if __name__ == '__main__':
mydb = pm.connect(host="localhost", # setting up connection
user="root",
passwd="root",
database="retailstore")
print("Connection is successful")
cur = mydb.cursor();
l = read_csv('admin.csv')
x = 100;
y = 0
for i in l:
id = "A" + str(x+y)
y+=1
email = i[1]
fname = i[2]
lname = i[3]
password = i[4]
sql = 'INSERT INTO administrator values(%s,%s,%s,%s,%s);'
val = (id,email,fname,lname,password)
print(val)
cur.execute(sql, val)
mydb.commit()