mirror of
				https://gitea.augustin64.fr/piair/MsRewards-Reborn.git
				synced 2025-11-03 23:23:53 +01:00 
			
		
		
		
	Update db.py
Just making sure points is not `None` (when it is not possible to get the number of points for example)
This commit is contained in:
		@@ -33,35 +33,38 @@ def get_row(compte, points, mycursor, same_points = True): #return if there is a
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def add_to_database(compte, points, sql_host,sql_usr,sql_pwd,sql_database, save_if_fail=True):
 | 
					def add_to_database(compte, points, sql_host,sql_usr,sql_pwd,sql_database, save_if_fail=True):
 | 
				
			||||||
    try:
 | 
					    if points is None:
 | 
				
			||||||
        mydb = mysql.connector.connect(
 | 
					        pass
 | 
				
			||||||
            host=sql_host,
 | 
					    else:
 | 
				
			||||||
            user=sql_usr,
 | 
					        try:
 | 
				
			||||||
            password=sql_pwd,
 | 
					            mydb = mysql.connector.connect(
 | 
				
			||||||
            database = sql_database
 | 
					                host=sql_host,
 | 
				
			||||||
        )
 | 
					                user=sql_usr,
 | 
				
			||||||
        mycursor = mydb.cursor()
 | 
					                password=sql_pwd,
 | 
				
			||||||
 | 
					                database = sql_database
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					            mycursor = mydb.cursor()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if get_row(compte, points,mycursor, True): #check if the row exist with the same ammount of points and do nothind if it does
 | 
					            if get_row(compte, points,mycursor, True): #check if the row exist with the same ammount of points and do nothind if it does
 | 
				
			||||||
            #printf("les points sont deja bon")
 | 
					                #printf("les points sont deja bon")
 | 
				
			||||||
            #return(0)
 | 
					                #return(0)
 | 
				
			||||||
            pass
 | 
					                pass
 | 
				
			||||||
        elif get_row(compte, points,mycursor, False) : #check if the row exist, but without the same ammount of points and update the point account then
 | 
					            elif get_row(compte, points,mycursor, False) : #check if the row exist, but without the same ammount of points and update the point account then
 | 
				
			||||||
            update_row(compte, points,mycursor,mydb)
 | 
					                update_row(compte, points,mycursor,mydb)
 | 
				
			||||||
            #printf("row updated")
 | 
					                #printf("row updated")
 | 
				
			||||||
            #return(1)
 | 
					                #return(1)
 | 
				
			||||||
        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)
 | 
				
			||||||
            #return(2) #printf("row added")
 | 
					                #return(2) #printf("row added")
 | 
				
			||||||
        if int(points) > 10 :
 | 
					            if int(points) > 10 :
 | 
				
			||||||
            update_last(compte, points, mycursor, mydb)
 | 
					                update_last(compte, points, mycursor, mydb)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        mycursor.close()
 | 
					            mycursor.close()
 | 
				
			||||||
        mydb.close()
 | 
					            mydb.close()
 | 
				
			||||||
    except BaseException as e:
 | 
					        except BaseException as e:
 | 
				
			||||||
        if save_if_fail:
 | 
					            if save_if_fail:
 | 
				
			||||||
            print("\nLes points n'ont pas pu être ajoutés, enregistrement dans le fichier 'points.csv'\n")
 | 
					                print("\nLes points n'ont pas pu être ajoutés, enregistrement dans le fichier 'points.csv'\n")
 | 
				
			||||||
            with open("points.csv", "a") as file:
 | 
					                with open("points.csv", "a") as file:
 | 
				
			||||||
                file.write(f"{compte},{points}\n")
 | 
					                    file.write(f"{compte},{points}\n")
 | 
				
			||||||
        raise e
 | 
					            raise e
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user