#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
测试百家号Cookie API调用
"""

import asyncio
import aiohttp
import json
import sys
import os

# 添加路径
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from platforms.baijiahao import BaijiahaoPublisher

async def test_baijiahao_api():
    """测试百家号API调用"""
    print("=" * 60)
    print("测试百家号API调用")
    print("=" * 60)
    
    # 这里需要替换为实际的Cookie
    test_cookie = input("请输入百家号Cookie（从浏览器登录后获取）: ").strip()
    
    if not test_cookie:
        print("Cookie 不能为空")
        return
    
    publisher = BaijiahaoPublisher(headless=True)
    
    try:
        # 测试获取账号信息
        print("\n1. 测试获取账号信息...")
        result = await publisher.get_account_info(test_cookie)
        print(f"结果: {json.dumps(result, ensure_ascii=False, indent=2)}")
        
        # 测试检查登录状态
        print("\n2. 测试检查登录状态...")
        status = await publisher.check_login_status(test_cookie)
        print(f"状态: {json.dumps(status, ensure_ascii=False, indent=2)}")
        
        # 测试获取作品列表
        print("\n3. 测试获取作品列表...")
        works = await publisher.get_works(test_cookie, 0, 10)
        print(f"作品: {json.dumps(works.to_dict(), ensure_ascii=False, indent=2)}")
        
    except Exception as e:
        print(f"测试失败: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    asyncio.run(test_baijiahao_api())