Update db.py

This commit is contained in:
Augustin 2022-11-16 18:13:36 +01:00 committed by GitHub
parent ebb1a8e48f
commit 80286b6a05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,7 +32,8 @@ def get_row(compte, points, mycursor, same_points = True): #return if there is a
return(len(myresult) == 1) return(len(myresult) == 1)
def add_to_database(compte, points, sql_host,sql_usr,sql_pwd,sql_database ): def add_to_database(compte, points, sql_host,sql_usr,sql_pwd,sql_database, save_if_fail=True):
try:
mydb = mysql.connector.connect( mydb = mysql.connector.connect(
host=sql_host, host=sql_host,
user=sql_usr, user=sql_usr,
@ -57,5 +58,10 @@ def add_to_database(compte, points, sql_host,sql_usr,sql_pwd,sql_database ):
mycursor.close() mycursor.close()
mydb.close() mydb.close()
except BaseException as e:
if save_if_fail:
print("\nLes points n'ont pas pu être ajoutés, enregistrement dans le fichier 'points.csv'\n")
with open("points.csv", "a") as file:
file.write(f"{compte},{points}\n")
raise e