fix: 合规审查卡死修复 + 小红书复制格式 + today-only过滤

This commit is contained in:
Yuzhiran Dev
2026-05-27 18:25:30 +08:00
parent 6585909ffc
commit bd3228806d
14 changed files with 278 additions and 148 deletions
+16 -7
View File
@@ -8,7 +8,7 @@ from pathlib import Path
from typing import Dict, List, Optional, Tuple
from dataclasses import dataclass, asdict
PROJECT_ROOT = Path('/root/openclaw-workspace/projects/yu-zhi-ran')
PROJECT_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(PROJECT_ROOT))
sys.path.insert(0, str(PROJECT_ROOT / "platform" / "backend"))
@@ -92,9 +92,9 @@ def load_topic_map():
topics = export_topics_to_json()
return {t['id']: t for t in topics}
def get_articles_from_db(topic_ids: Optional[List[str]] = None) -> List[Tuple[str, str, str]]:
def get_articles_from_db(topic_ids: Optional[List[str]] = None, today_only: bool = False) -> List[Tuple[str, str, str]]:
"""从 articles 表读取 HTML 内容
Returns: [(html_content, platform, topic_id), ...]
"""
from db_helper import get_articles_by_topic
@@ -110,9 +110,14 @@ def get_articles_from_db(topic_ids: Optional[List[str]] = None) -> List[Tuple[st
else:
from app.database import SessionLocal
from app.models import Article
from sqlalchemy import func
db = SessionLocal()
try:
all_articles = db.query(Article).filter(Article.html_content.isnot(None)).all()
query = db.query(Article).filter(Article.html_content.isnot(None))
if today_only:
cutoff = datetime.datetime.now() - datetime.timedelta(hours=24)
query = query.filter(Article.created_at >= cutoff)
all_articles = query.all()
for a in all_articles:
results.append((a.html_content, a.platform, a.topic_id))
finally:
@@ -222,14 +227,17 @@ def _load_platform_configs() -> Dict[str, Dict]:
finally:
db.close()
def main(topic_ids: List[str] = None):
def main(topic_ids: List[str] = None, today_only: bool = False):
logger.info("=== 合规审查与优化开始 ===")
logger.info("LLM 配置: opencode-go (model=deepseek-v4-flash) — 固定用于合规审查")
platform_configs = _load_platform_configs()
logger.info(f"已加载 {len(platform_configs)} 个平台配置")
articles = get_articles_from_db(topic_ids)
if today_only:
logger.info("仅处理当天创建的选题文章")
articles = get_articles_from_db(topic_ids, today_only)
if not articles:
logger.warning("未找到任何文章(可能尚未创作或同步到 DB)")
report_file = DRAFTS_DIR / TODAY / "optimization_report.json"
@@ -349,6 +357,7 @@ if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description='合规审查与优化任务')
parser.add_argument('--topic-ids', help='逗号分隔的选题ID列表,例如: A01,B02')
parser.add_argument('--today-only', action='store_true', help='仅处理当天创建的选题文章')
args = parser.parse_args()
topic_ids = args.topic_ids.split(',') if args.topic_ids else None
main(topic_ids)
main(topic_ids, today_only=args.today_only)