update_imd_band.py 884 Bytes
Newer Older
1
2
import mysql.connector

Stefan Vercillo's avatar
Stefan Vercillo committed
3
cnx = mysql.connector.connect(host='localhost', user='snvercil', database='Education', password="pass")
4
5
6
7
8
9
cursor = cnx.cursor()

cursor.execute("SELECT * FROM studentInfo;")

c = cursor.fetchall()
for row in c:
Stefan Vercillo's avatar
Stefan Vercillo committed
10
    d = row[2]
Stefan Vercillo's avatar
cli    
Stefan Vercillo committed
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
    if d == "" or d is None:
        d = -1
    elif d == "0-10%":
        d = 10
    elif d == "10-20":
        d = 20
    elif d == "20-30%":
        d = 30
    elif d == "30-40%":
        d = 40
    elif d == "40-50%":
        d = 50
    elif d == "50-60%":
        d = 60
    elif d == "60-70%":
        d = 70
    elif d == "70-80%":
        d = 80
    elif d == "80-90%":
        d = 90
    elif d == "90-100%":
        d = 100

    s = f"update studentInfo set imd_band = {d} where id_student = {row[0]}"
Stefan Vercillo's avatar
Stefan Vercillo committed
36
    print(s)
37
38
39
40
41
42
    cursor.execute(s)

# Make sure data is committed to the database
cnx.commit()

cursor.close()
Stefan Vercillo's avatar
cli    
Stefan Vercillo committed
43
cnx.close()