import edward
All checks were successful
Gitea Actions Demo / deploy (push) Successful in 15s

This commit is contained in:
konjacpotato
2025-11-12 21:19:26 +08:00
commit 5267db8a0d
48 changed files with 1848 additions and 0 deletions

View File

@ -0,0 +1,49 @@
import re
import time
from database.database import get_session
from database.tcontentdispatch.curd import get_content_by_title_and_category, create_or_update_content
from database.tcontentdispatch.model import TContentDispatch
from database.tmaterial.crud import update_material_by_id, \
get_materials_for_generate_news
from log.log_manager import log
from task.manager_task import execute_task
def generate_news_task():
with get_session() as db:
# 1. 构建今日新闻文章标题格式今日新闻yyyy-MM-dd
title = ("今日新闻" +
time.strftime("%Y", time.localtime()) + '' +
time.strftime("%m", time.localtime()) + '' +
time.strftime("%d", time.localtime()) + '')
# 2. 从内容分发数据表获取当前标题和分类的文章是否存在
content_dispatch = get_content_by_title_and_category(db, title, "新鲜事")
content = ""
if content_dispatch is not None:
content = content_dispatch.content
# 从最后一条获取并计算开始编号
result = re.findall(r'(?<!\.)\d+\. ', content)
start_num = int(re.findall(r'\d+', result[-1])[-1]) + 1
else:
content_dispatch = TContentDispatch(category="新鲜事", title=title, ai_generate=1)
start_num = 1
# 3. 从新闻素材数据表获取房产类的新闻列表
news_list = get_materials_for_generate_news(db)
# 4. 拼接成文章正文content
for i, news in enumerate(news_list, start=start_num): # Using enumerate to control the index starting from 1
content += f"{i}. {news.ai_summary}\n"
# 5. 把content写入数据库
if content is not None and content != "" and news_list is not None:
content_dispatch.content = content
content_dispatch.is_sent = False
create_or_update_content(db, content_dispatch)
# 6. 把news_list更新入数据库更新字段is_usage为True
for news in news_list:
news.is_usage = True
update_material_by_id(db, news)
log(f"generate_news_task finish, news count {start_num + len(news_list)}")
if __name__ == "__main__":
execute_task(generate_news_task)

54
task/news/revisal.py Normal file
View File

@ -0,0 +1,54 @@
import time
from database.database import get_session
from database.tcontentdispatch.curd import get_content_by_title_and_category, update
from llm.local.ollama import Ollama
from log.log_manager import log
from task.manager_task import execute_task
def ai_edit(input_message: str) -> str:
log(f"ai_edit start execute at {time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}")
ollama = Ollama()
response = ollama.generate_text(input_message)
log(f"ai_edit end execute at {time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}")
return response
def revisal_task():
with get_session() as db:
# 1. 构建今日新闻文章标题格式今日新闻yyyy-MM-dd
title = ("今日新闻" +
time.strftime("%Y", time.localtime()) + '' +
time.strftime("%m", time.localtime()) + '' +
time.strftime("%d", time.localtime()) + '')
# 2. 从内容分发数据表获取当前标题和分类的文章是否存在
content_dispatch = get_content_by_title_and_category(db, title, "新鲜事")
ai_content = ""
if content_dispatch and content_dispatch.content:
# 3. 执行AI编辑
input_message = (('按照规则编辑提供的内容。规则如下:\n'
'1 去除重复内容\n'
'2 不要故意删除内容\n'
'3 重新编号\n'
'4 不要出现空行\n'
'5 不要出现类似"以下是根据您提供的规则编辑后的内容"等提示信息,直接输出编辑后的内容\n'
'内容如下:\n')
+ content_dispatch.content)
ai_content = ai_edit(input_message)
print(content_dispatch.content)
print("-----------------------------------------------------------")
print(ai_content)
# 4. 去掉ai_content中的空行
ai_content = "\n".join([line for line in ai_content.split("\n") if line.strip()])
# 5. 把content写入数据库
if ai_content:
content_dispatch.ai_content = ai_content
content_dispatch.is_sent = False
update(db)
# 获取ai_content的行数
lines = ai_content.strip().split("\n")
log(f"revisal news task finish, news count: {len(lines)}, news words: {len(ai_content)}")
if __name__ == "__main__":
execute_task(revisal_task)