12.20
今天修改故事系统代码import pymysql
连接MySQL数据库
conn = pymysql.connect(
host='localhost',
user='root',
password='cyy1811068002',
database='stories',
charset='utf8mb4'
)
cursor = conn.cursor()
查询所有故事
cursor.execute("SELECT id, title, image_url FROM story")
stories = cursor.fetchall()
print(f"共有 {len(stories)} 个故事")
print("\n故事列表:")
for story in stories:
id, title, image_url = story
has_image = "✓ 有图片" if image_url else "✗ 无图片"
print(f"ID: {id}, 标题: {title}, 图片状态: {has_image}")
找出没有图片的故事
stories_without_images = [story for story in stories if not story[2]]
print(f"\n没有图片的故事: {len(stories_without_images)} 个")
if stories_without_images:
print("\n需要生成图片的故事ID和标题:")
for story in stories_without_images:
print(f"ID: {story[0]}, 标题: {story[1]}")
关闭数据库连接
conn.close()

浙公网安备 33010602011771号