53 lines
2.0 KiB
Python
53 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
检查数据库中的宝箱数据
|
|
"""
|
|
import sqlite3
|
|
from datetime import datetime
|
|
|
|
def check_chests():
|
|
"""检查宝箱数据"""
|
|
print("=== 检查数据库中的宝箱数据 ===")
|
|
|
|
try:
|
|
# 连接到数据库
|
|
conn = sqlite3.connect('treasure_box_game.db')
|
|
cursor = conn.cursor()
|
|
|
|
# 查询所有宝箱
|
|
cursor.execute("SELECT id, title, created_at, countdown_seconds, status FROM chests")
|
|
chests = cursor.fetchall()
|
|
|
|
print("宝箱数据:")
|
|
print("ID | Title | Created At | Countdown Seconds | Status")
|
|
print("---|-------|------------|------------------|-------")
|
|
|
|
for chest in chests:
|
|
chest_id, title, created_at, countdown_seconds, status = chest
|
|
print(f"{chest_id} | {title} | {created_at} | {countdown_seconds} | {status}")
|
|
|
|
# 解析创建时间
|
|
try:
|
|
# 处理MySQL的datetime格式
|
|
if 'T' in created_at:
|
|
# ISO格式
|
|
created_time = datetime.fromisoformat(created_at.replace('Z', '+00:00'))
|
|
else:
|
|
# MySQL datetime格式 (YYYY-MM-DD HH:MM:SS)
|
|
created_time = datetime.strptime(created_at, '%Y-%m-%d %H:%M:%S')
|
|
|
|
now = datetime.utcnow() # 使用UTC时间进行计算
|
|
elapsed = (now - created_time).total_seconds()
|
|
time_remaining = max(0, int(countdown_seconds - elapsed))
|
|
print(f" -> Created: {created_time}")
|
|
print(f" -> Now (UTC): {now}")
|
|
print(f" -> Elapsed: {elapsed:.2f}s, Time remaining: {time_remaining}s")
|
|
except Exception as e:
|
|
print(f" -> Error calculating time: {e}")
|
|
|
|
conn.close()
|
|
except Exception as e:
|
|
print(f"数据库连接错误: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
check_chests() |