#!/usr/bin/env python3 """ 合规审查与优化任务(数据库版) 每天 05:45 运行,处理当天所有 draft 文章: 1. 执行合规检查(compliance_checker) 2. 自动修复已知问题(标题、标签) 3. 重写合规版本 4. 更新选题状态为「待发布」 5. 生成优化报告通知 """ import json, datetime, logging, sys, re from pathlib import Path from typing import Dict, List from dataclasses import dataclass, asdict PROJECT_ROOT = Path('/root/openclaw-workspace/projects/yu-zhi-ran') sys.path.insert(0, str(PROJECT_ROOT)) from scripts.compliance_checker import check_article # 导入 LLM 客户端(合规优化使用 NVIDIA) sys.path.insert(0, str(PROJECT_ROOT / "platform" / "backend")) try: from app.core.modelscope_client import call_llm HAVE_LLM = True except ImportError: HAVE_LLM = False # 导入数据库辅助模块 from db_helper import get_topic_by_id, update_topic_status DATA_DIR = PROJECT_ROOT / "automation" / "data" RELEASES_DIR = DATA_DIR / "releases" DRAFTS_DIR = DATA_DIR / "drafts" LOGS_DIR = PROJECT_ROOT / "automation" / "logs" TODAY = datetime.datetime.now().strftime("%Y-%m-%d") logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', handlers=[logging.FileHandler(LOGS_DIR / f"optimizer_{TODAY}.log"), logging.StreamHandler()]) logger = logging.getLogger(__name__) # 平台白名单标签 PLATFORM_TAGS = { "zhihu": ["科技", "职场"], "xiaohongshu": ["AI", "可持续", "生活方式"] } @dataclass class OptimizationResult: file: str platform: str topic_id: str title: str original_issues: int fixed_issues: int final_score: int status: str def load_topic_map(): """从数据库加载所有选题数据""" from db_helper import export_topics_to_json topics = export_topics_to_json() return {t['id']: t for t in topics} def update_topic_status_db_only(topic_id: str, status: str): """仅更新数据库状态(不更新JSON)""" from db_helper import update_topic_status update_topic_status(topic_id, status) def fix_wechat_title(html: str, title: str) -> str: """微信标题优化: