添加了创建key工具和删除空key工具

This commit is contained in:
Kakune55 2023-11-04 20:11:57 +08:00
parent 1c36a170b0
commit 02f1140434
3 changed files with 49 additions and 0 deletions

26
createKey.py Normal file
View File

@ -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()

19
deleteEmptyKey.py Normal file
View File

@ -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("已完成删除")

View File

@ -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