fix: 合规审查卡死修复 + 小红书复制格式 + today-only过滤
This commit is contained in:
@@ -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)
|
||||
|
||||
+6
-5
@@ -28,7 +28,7 @@ logging.basicConfig(
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def select_next_topic(topic_id: str = None) -> Dict:
|
||||
def select_next_topic(topic_id: str = None, today_only: bool = False) -> Dict:
|
||||
"""选择并锁定要创作的选题(趋势引擎匹配 → 回退优先级)"""
|
||||
if topic_id:
|
||||
topic = get_topic_by_id(topic_id)
|
||||
@@ -50,7 +50,7 @@ def select_next_topic(topic_id: str = None) -> Dict:
|
||||
except Exception as e:
|
||||
logger.warning(f"选题引擎失效,回退简单策略: {e}")
|
||||
|
||||
topic = get_next_topic(priority='高') or get_next_topic()
|
||||
topic = get_next_topic(priority='高', today_only=today_only) or get_next_topic(today_only=today_only)
|
||||
if not topic:
|
||||
raise ValueError("No available topics to create (all locked or wrong status)")
|
||||
update_topic_status(topic['id'], 'review')
|
||||
@@ -80,11 +80,11 @@ def run_optimizer_step(topic_id: str) -> bool:
|
||||
logger.info(f"compliance_optimizer 完成: {result.stdout.strip()}")
|
||||
return True
|
||||
|
||||
def run_pipeline(topic_id: str = None) -> Dict:
|
||||
def run_pipeline(topic_id: str = None, today_only: bool = False) -> Dict:
|
||||
"""运行完整流水线:研究 → 大纲 → 撰写 → 合规优化"""
|
||||
tid = None
|
||||
try:
|
||||
topic = select_next_topic(topic_id)
|
||||
topic = select_next_topic(topic_id, today_only)
|
||||
tid = topic['id']
|
||||
logger.info(f"开始创作流水线: topic_id={tid}, title={topic.get('title')}")
|
||||
|
||||
@@ -127,9 +127,10 @@ def main():
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser(description='内容创作流水线(研究→大纲→撰写→合规优化)')
|
||||
parser.add_argument('--topic-id', help='指定选题ID,不指定则自动选择待处理选题')
|
||||
parser.add_argument('--today-only', action='store_true', help='仅处理当天创建的选题')
|
||||
args = parser.parse_args()
|
||||
|
||||
result = run_pipeline(args.topic_id)
|
||||
result = run_pipeline(args.topic_id, today_only=args.today_only)
|
||||
print(json.dumps(result, ensure_ascii=False))
|
||||
sys.exit(0 if result['ok'] else 1)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
from datetime import datetime, date
|
||||
from datetime import datetime, date, timedelta
|
||||
from typing import Optional, Dict, List
|
||||
|
||||
# 加载 .env(在 scripts/ 目录下运行时需要)
|
||||
@@ -53,7 +53,7 @@ def get_topics_by_status(status: str, db: Optional[Session] = None) -> List[Dict
|
||||
if close_db:
|
||||
db.close()
|
||||
|
||||
def get_next_topic(priority: Optional[str] = None, db: Optional[Session] = None) -> Optional[Dict]:
|
||||
def get_next_topic(priority: Optional[str] = None, db: Optional[Session] = None, today_only: bool = False) -> Optional[Dict]:
|
||||
"""获取下一个待处理的选题(状态为 pending/待处理)"""
|
||||
close_db = False
|
||||
if db is None:
|
||||
@@ -65,6 +65,9 @@ def get_next_topic(priority: Optional[str] = None, db: Optional[Session] = None)
|
||||
query = db.query(Topic).filter(Topic.status.in_(status_filter))
|
||||
if priority:
|
||||
query = query.filter(Topic.priority == priority)
|
||||
if today_only:
|
||||
cutoff = datetime.now() - timedelta(hours=24)
|
||||
query = query.filter(Topic.created_at >= cutoff)
|
||||
topic = query.order_by(Topic.priority_score.desc().nullslast(), Topic.created_at.asc()).first()
|
||||
return topic_to_dict(topic) if topic else None
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user