update point

This commit is contained in:
piair 2022-06-09 16:23:13 +02:00
parent b7f3bd053a
commit 4f29e876b1

9
V4.py
View File

@ -130,6 +130,13 @@ def update_row(compte, points, mycursor, mydb):
printf(mycursor.rowcount, "record(s) updated") printf(mycursor.rowcount, "record(s) updated")
def update_last(compte, points, mycursor, mydb):
sql = f"UPDATE comptes SET last_pts = {points} WHERE compte = '{compte}';"
mycursor.execute(sql)
mydb.commit()
printf(mycursor.rowcount, "record(s) updated")
def get_row(compte, points, mycursor, same_points = True): #return if there is a line with the same ammount of point or with the same name as well as the same day def get_row(compte, points, mycursor, same_points = True): #return if there is a line with the same ammount of point or with the same name as well as the same day
if same_points : if same_points :
mycursor.execute(f"SELECT * FROM daily WHERE points = {points} AND compte = '{compte}' AND date = current_date() ;") mycursor.execute(f"SELECT * FROM daily WHERE points = {points} AND compte = '{compte}' AND date = current_date() ;")
@ -156,6 +163,8 @@ def add_to_database(compte, points):
else : # if the row don't exist, create it with the good ammount of points else : # if the row don't exist, create it with the good ammount of points
add_row(compte, points,mycursor,mydb) add_row(compte, points,mycursor,mydb)
printf("row added") printf("row added")
if points > 10 :
update_last(compte, points, mycursor, mydb)
mycursor.close() mycursor.close()
mydb.close() mydb.close()