#!/usr/bin/env python3
"""批量将文章从草稿转为已发布"""
import xmlrpc.client
import time

WP_URL = "https://dianziqianzhang.com/xmlrpc.php"
WP_USERNAME = "admin"
WP_PASSWORD = "VCLxs8476YWM"
WP_BLOG_ID = "1"

# 需要发布的文章ID列表（包含之前的200）
POST_IDS = [200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 
            220, 222, 224, 226, 228, 230, 232, 234, 236, 238, 240]

server = xmlrpc.client.ServerProxy(WP_URL)

success = 0
fail = 0

for pid in POST_IDS:
    try:
        # 先获取当前文章信息
        post = server.wp.getPost(WP_BLOG_ID, WP_USERNAME, WP_PASSWORD, pid)
        title = post.get('post_title', f'文章#{pid}')
        
        # 更新状态为publish
        result = server.wp.editPost(WP_BLOG_ID, WP_USERNAME, WP_PASSWORD, pid, {
            'post_status': 'publish',
            'post_date': time.strftime('%Y%m%dT%H:%M:%S')
        })
        
        if result:
            print(f"  ✅ [{pid}] {title}")
            success += 1
        else:
            print(f"  ❌ [{pid}] 发布失败")
            fail += 1
            
    except Exception as e:
        print(f"  ❌ [{pid}] 错误: {e}")
        fail += 1

print(f"\n✅ 发布完成！成功: {success}, 失败: {fail}")
