#!/usr/bin/env python3
import json, datetime
from pathlib import Path

PROJECT_ROOT = Path(__file__).parent.parent
data_dir = PROJECT_ROOT / "automation" / "data"
releases_dir = data_dir / "releases" / "2026-04-16"
drafts_dir = data_dir / "drafts" / "2026-04-16"

# 1. 选题状态
topics = json.load(open(data_dir / "sustainability_topics.json", encoding='utf-8'))
by_status = {}
for t in topics:
    s = t.get('status','待处理')
    by_status.setdefault(s, []).append(t)

print(f"📊 宇之然内容生成系统状态报告 ({datetime.date.today()})")
print(f"\n=== 1. 选题库总览 ===")
print(f"总选题数: {len(topics)}")
for s, arr in sorted(by_status.items()):
    print(f"  {s}: {len(arr)} 个")

# 2. 今日生成内容
print(f"\n=== 2. 今日 (2026-04-16) 已生成内容 ===")
if releases_dir.exists():
    zhihu = list((releases_dir / 'zhihu').glob('*.html'))
    wechat = list((releases_dir / 'wechat').glob('*.html'))
    xhs = list((releases_dir / 'xiaohongshu').glob('*.html'))
    print(f"  知乎: {len(zhihu)} 篇")
    print(f"  微信公众号: {len(wechat)} 篇")
    print(f"  小红书: {len(xhs)} 篇")
    # 列出选题ID
    topic_ids = set()
    for f in zhihu:
        topic_ids.add(f.stem.split('_')[1])
    print(f"  涉及选题ID: {', '.join(sorted(topic_ids))}")
else:
    print("  今日无发布内容")

# 3. 合规与优化结果
report_file = drafts_dir / "optimization_report.json"
if report_file.exists():
    report = json.load(open(report_file, encoding='utf-8'))
    print(f"\n=== 3. 合规优化结果 ===")
    sm = report['summary']
    print(f"  总文章数: {sm['total_articles']}")
    print(f"  自动通过: {sm['passed_auto']} 篇")
    print(f"  需人工审核: {sm['need_manual']} 篇")
    print(f"  平均合规分: {sm['average_score']:.1f}")
    if sm['need_manual'] == 0:
        print("  ✅ 所有文章均已自动合规")
else:
    print("\n=== 3. 合规优化结果 ===")
    print("  未找到优化报告")

# 4. 待发布选题（可发布）
print(f"\n=== 4. 待发布选题（已合规）===")
ready = by_status.get('待发布', [])
if ready:
    for t in sorted(ready, key=lambda x: x.get('priority_score',0), reverse=True):
        print(f"  {t['id']}: {t['title'][:50]}")
else:
    print("  暂无待发布选题")

print(f"\n=== 5. 操作提示 ===")
print("1. 人工发布：将「待发布」选题的HTML发布到对应平台")
print("2. 发布后运行: python3 scripts/mark_published.py <选题ID>")
print("3. 或批量发布: python3 scripts/mark_published.py --all-ready")
