Files
peter/seek/zhihu_com/demo.py
konjacpotato 8c1a740f0b import peter
2025-11-12 20:42:16 +08:00

26 lines
1.1 KiB
Python

from database.database import get_session
from database.thotcontent.crud import get_hot_content_by_topic_id
from database.thottopic.crud import get_latest_hot_topic
if __name__ == '__main__':
with get_session() as db:
# 1. 获取最新的热点话题
latest_hot_topic = get_latest_hot_topic(db)
topic = latest_hot_topic.topic
print(latest_hot_topic)
# 2. 获取话题内容
hot_contents = get_hot_content_by_topic_id(db, latest_hot_topic.id)
for hot_content in hot_contents:
print(hot_content)
# 统计hot_content.content的字数
print(len(hot_content.content))
topic_content = [hot_content.content for hot_content in hot_contents]
print(topic_content)
print(len(topic_content))
print('---------------------------------------------------------------')
print(topic_content[0])
print('---------------------------------------------------------------')
print(topic_content[1])
print('---------------------------------------------------------------')
print(topic_content[2])