54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
创建一个测试宝箱
|
||
"""
|
||
import pymysql
|
||
from datetime import datetime
|
||
|
||
def create_test_chest():
|
||
"""创建测试宝箱"""
|
||
print("=== 创建测试宝箱 ===")
|
||
|
||
try:
|
||
# 连接到MySQL数据库
|
||
connection = pymysql.connect(
|
||
host='localhost',
|
||
user='root',
|
||
password='taiyi1224',
|
||
database='baoxiang',
|
||
charset='utf8mb4'
|
||
)
|
||
|
||
with connection.cursor() as cursor:
|
||
# 插入一个新的测试宝箱
|
||
sql = """
|
||
INSERT INTO chests
|
||
(streamer_id, title, option_a, option_b, status, countdown_seconds, created_at)
|
||
VALUES (%s, %s, %s, %s, %s, %s, %s)
|
||
"""
|
||
|
||
# 创建一个5分钟倒计时的宝箱
|
||
cursor.execute(sql, (
|
||
1, # streamer_id
|
||
"测试倒计时宝箱", # title
|
||
"选项A", # option_a
|
||
"选项B", # option_b
|
||
"BETTING", # status (0 = BETTING)
|
||
300, # countdown_seconds (5分钟)
|
||
datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S') # created_at
|
||
))
|
||
|
||
# 获取插入的宝箱ID
|
||
chest_id = cursor.lastrowid
|
||
|
||
# 提交事务
|
||
connection.commit()
|
||
|
||
print(f"成功创建测试宝箱,ID: {chest_id}")
|
||
|
||
connection.close()
|
||
except Exception as e:
|
||
print(f"MySQL数据库连接错误: {e}")
|
||
|
||
if __name__ == "__main__":
|
||
create_test_chest() |