task: add real estate story
All checks were successful
Gitea Actions Demo / deploy (push) Successful in 26s

This commit is contained in:
konjacpotato
2026-02-15 15:29:13 +08:00
parent 5267db8a0d
commit 1e2d739d00
20 changed files with 554 additions and 10 deletions

View File

@ -0,0 +1,42 @@
from datetime import datetime
import json
from task.manager_task import execute_task
from config.database import SessionLocal
from models import SourceContent, Article
from utils import logger
from llm import LLMThinkingEngine
def story_edit_task():
with SessionLocal() as db:
# 获取今天的所有帖子信息
today_contents = db.query(SourceContent).filter(
SourceContent.create_time >= datetime.today().replace(hour=0, minute=0, second=0, microsecond=0)
).limit(10).all()
if len(today_contents) == 0:
logger.info("story_edit_task finish, content size 0")
return
logger.info(f"story_edit_task get {len(today_contents)} contents")
llm_engine = LLMThinkingEngine(system_prompt_file="real_estate_story_system_prompt.txt")
for content in today_contents:
logger.info(f"story_edit_task content id: {content.id}, title: {content.link}, platform: {content.platform}")
story = llm_engine.think(f"故事素材:{content.content}")
logger.info(f"story_edit_task content id: {content.id} story: {story}")
# 将生成的故事写入Article表
json_story = json.loads(story)
title = json_story.get("title", "无标题")
paragraphs = json_story.get("body", ["无内容"])
article_content = "\n".join(paragraphs)
article = Article(
title=title,
keywords=None,
content=article_content,
used=False
)
db.add(article)
db.commit()
# break # 目前先处理一条内容,后续再改成批量处理
if __name__ == "__main__":
execute_task(story_edit_task)

View File

@ -7,7 +7,7 @@ from apscheduler.schedulers.blocking import BlockingScheduler
from config import config
from database.database import get_session
from database.tscheduler.crud import get_tasks_by_executor
from log.log_manager import log
from utils import logger
"""
这是一个特殊的任务,负责管理任务,命名为管理者任务。
@ -26,10 +26,10 @@ def log_task_execution(task_name: str, start_time: float, end_time: float = None
start_time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(start_time))
end_time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(end_time))
if end_time is None:
log(f"{task_name} start execute at {start_time_str}")
logger.info(f"{task_name} start execute at {start_time_str}")
else:
elapsed_time = end_time - start_time
log(f"{task_name} end execute at {end_time_str}, use time {elapsed_time:.2f} seconds")
logger.info(f"{task_name} end execute at {end_time_str}, use time {elapsed_time:.2f} seconds")
def execute_task(task: callable):
@ -65,7 +65,7 @@ def load_tasks(scheduler: BlockingScheduler):
id=str(task_id),
replace_existing=True
)
log(f"Task {task.task_name} added with interval {interval_seconds} seconds")
logger.info(f"Task {task.task_name} added with interval {interval_seconds} seconds")
elif trigger == "cron":
# 解析 cron 表达式的字段
fields = task.cron_expression.split()
@ -89,7 +89,7 @@ def load_tasks(scheduler: BlockingScheduler):
id=str(task_id),
replace_existing=True
)
log(f"Task {task.task_name} added with cron {task.cron_expression}")
logger.info(f"Task {task.task_name} added with cron {task.cron_expression}")
elif trigger == "date":
scheduler.add_job(
task_function,
@ -98,9 +98,9 @@ def load_tasks(scheduler: BlockingScheduler):
id=str(task_id),
replace_existing=True
)
log(f"Task {task.task_name} added with date {task.execution_date}")
logger.info(f"Task {task.task_name} added with date {task.execution_date}")
else:
log(f"Invalid trigger type: {trigger}")
logger.warning(f"Invalid trigger type: {trigger}")
# 管理者任务