# -*- coding: utf-8 -*-
"""
打包百家号 Skill
===============
将 Skill 打包成 zip 文件，方便分享给其他电脑使用

用法：
    python pack_skill.py

输出：
    baijiahao-skill-v{版本号}.zip
"""
import os
import sys
import zipfile
from datetime import datetime

sys.stdout.reconfigure(encoding='utf-8')

def pack_skill():
    """打包 Skill 文件"""
    
    # Skill 根目录
    skill_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    
    # 版本号（使用日期）
    version = datetime.now().strftime("%Y%m%d")
    output_file = os.path.join(skill_dir, f"baijiahao-skill-v{version}.zip")
    
    # 需要包含的文件
    include_files = [
        'SKILL.md',
        'README.md',
        'scripts/start_chrome_bjh.py',
        'scripts/bjh_navigate_cdp.py',
        'scripts/bjh_fill_article_v8.py',
        'scripts/batch_bjh.py',
        'scripts/bjh_diagnose.py',
    ]
    
    print("=" * 60)
    print("百家号 Skill 打包工具")
    print("=" * 60)
    print(f"\n版本: {version}")
    print(f"输出: {output_file}")
    print(f"\n包含文件:")
    
    # 创建 zip 文件
    with zipfile.ZipFile(output_file, 'w', zipfile.ZIP_DEFLATED) as zf:
        for file_path in include_files:
            full_path = os.path.join(skill_dir, file_path)
            if os.path.exists(full_path):
                zf.write(full_path, file_path)
                file_size = os.path.getsize(full_path)
                print(f"  ✓ {file_path} ({file_size} bytes)")
            else:
                print(f"  ✗ {file_path} (未找到)")
    
    # 显示结果
    output_size = os.path.getsize(output_file)
    print(f"\n" + "=" * 60)
    print(f"✅ 打包完成!")
    print(f"   文件: {output_file}")
    print(f"   大小: {output_size} bytes ({output_size/1024:.1f} KB)")
    print("=" * 60)
    
    print("\n使用说明:")
    print("  1. 将 zip 文件复制到目标电脑")
    print("  2. 解压到任意目录")
    print("  3. 进入 scripts 目录，运行: python batch_bjh.py")
    
    return output_file

if __name__ == "__main__":
    pack_skill()
