diff --git a/.gitignore b/.gitignore index d62b408..b0659a1 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ requirements.txt data **/__pycache__ /user_data +install.sh diff --git a/database.py b/database.py new file mode 100644 index 0000000..a386eb6 --- /dev/null +++ b/database.py @@ -0,0 +1,53 @@ +import mysql.connector +import configparser +from os import path + +config_path = "./user_data/config.cfg" +config = configparser.ConfigParser() +config.read(config_path) + +sql_usr = config["SQL"]["usr"] +sql_pwd = config["SQL"]["pwd"] +sql_host = config["SQL"]["host"] +sql_database = config["SQL"]["database"] + + +mydb = mysql.connector.connect( + host=sql_host, + user=sql_usr, + password=sql_pwd, + database = sql_database +) +mycursor = mydb.cursor() + +def add_account(name: str, endroit: str, proprio: str): + command = f'INSERT INTO comptes (compte, proprio, endroit, last_pts) VALUES ("{name}", "{proprio}", "{endroit}",0);' + mycursor.execute(command) + + +def ban_account(name: str, pts = 0): + + command1 = f"INSERT INTO banned (nom, total) VALUES ('{name}', {pts});" + command2 = f'DELETE FROM comptes WHERE compte = "{name}";' + mycursor.execute(command1) + mycursor.execute(command2) + +def update_pts(name: str, pts = 0): + pass + + +print("ajouter un compte : 1\nban un compte : 2") +i = input() +if i == "1": + name = input("quel est le nom ? ") + endroit = input("ou est le bot ? ") + proprio = input("qui est le proprio ? ") + add_account(name, endroit, proprio) +elif i == '2': + name = input("quel est le compte qui a été ban ? ") + pts = input("il avait combien de points ? ") + ban_account(name, pts) + +mydb.commit() +mycursor.close() +mydb.close()