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