48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
"""
|
|
检查数据库中的用户
|
|
"""
|
|
import sqlite3
|
|
import os
|
|
|
|
DB_PATH = "weibo_hotsign.db"
|
|
|
|
def check_database():
|
|
if not os.path.exists(DB_PATH):
|
|
print(f"❌ 数据库文件不存在: {DB_PATH}")
|
|
return
|
|
|
|
print(f"✓ 数据库文件存在: {os.path.abspath(DB_PATH)}")
|
|
print()
|
|
|
|
conn = sqlite3.connect(DB_PATH)
|
|
cursor = conn.cursor()
|
|
|
|
# 检查表
|
|
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
|
|
tables = cursor.fetchall()
|
|
print("数据库中的表:")
|
|
for table in tables:
|
|
print(f" - {table[0]}")
|
|
print()
|
|
|
|
# 检查用户
|
|
cursor.execute("SELECT id, username, email, is_active FROM users;")
|
|
users = cursor.fetchall()
|
|
|
|
if users:
|
|
print(f"找到 {len(users)} 个用户:")
|
|
for user in users:
|
|
print(f" ID: {user[0]}")
|
|
print(f" 用户名: {user[1]}")
|
|
print(f" 邮箱: {user[2]}")
|
|
print(f" 激活状态: {'是' if user[3] else '否'}")
|
|
print()
|
|
else:
|
|
print("❌ 数据库中没有用户!")
|
|
print("请运行: python create_sqlite_db.py")
|
|
|
|
conn.close()
|
|
|
|
if __name__ == "__main__":
|
|
check_database()
|