From 02f1140434f6492470e0fae5dc76b20235f33ea7 Mon Sep 17 00:00:00 2001 From: Kakune55 Date: Sat, 4 Nov 2023 20:11:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=88=9B=E5=BB=BAke?= =?UTF-8?q?y=E5=B7=A5=E5=85=B7=E5=92=8C=E5=88=A0=E9=99=A4=E7=A9=BAkey?= =?UTF-8?q?=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- createKey.py | 26 ++++++++++++++++++++++++++ deleteEmptyKey.py | 19 +++++++++++++++++++ server.py | 4 ++++ 3 files changed, 49 insertions(+) create mode 100644 createKey.py create mode 100644 deleteEmptyKey.py diff --git a/createKey.py b/createKey.py new file mode 100644 index 0000000..1efc26c --- /dev/null +++ b/createKey.py @@ -0,0 +1,26 @@ +import uuid , pymysql + +surplus = int(input("usrplus:")) +number = int(input("number:")) +#打开数据库连接 +db = pymysql.connect(host='www.kakuweb.top', + port=33306, + user='root', + password='KAku3.14159..', + database='AIapi') +# 使用 cursor() 方法创建一个游标对象 cursor +cursor = db.cursor() +for i in range(0,number): + tempuuid = uuid.uuid4() + print(tempuuid) + # 使用 execute() 方法执行 SQL 查询 + cursor.execute(f"INSERT INTO usersurplus (userkey, surplus) VALUES ('{tempuuid}', {surplus});") + +# 提交事务 +db.commit() + +# 关闭连接 +db.close() + +print("生成完成") +input() \ No newline at end of file diff --git a/deleteEmptyKey.py b/deleteEmptyKey.py new file mode 100644 index 0000000..6983908 --- /dev/null +++ b/deleteEmptyKey.py @@ -0,0 +1,19 @@ +import pymysql +#打开数据库连接 +db = pymysql.connect(host='www.kakuweb.top', + port=33306, + user='root', + password='KAku3.14159..', + database='AIapi') +# 使用 cursor() 方法创建一个游标对象 cursor +cursor = db.cursor() + +cursor.execute("DELETE FROM usersurplus WHERE surplus < 1;") + +# 提交事务 +db.commit() + +# 关闭连接 +db.close() + +print("已完成删除") diff --git a/server.py b/server.py index 66ccd36..775d137 100644 --- a/server.py +++ b/server.py @@ -48,6 +48,10 @@ def userSurplus(userkey): cursor.execute(f"SELECT surplus FROM usersurplus WHERE userkey = '{userkey}';") # 使用 fetchone() 方法获取单条数据. data = cursor.fetchone() + + # 关闭连接 + db.close() + if data != None: return data[0] return -99999