84 lines
2.3 KiB
Python
84 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
可行的解决方案 - 不使用继承来避免参数顺序问题
|
||
"""
|
||
|
||
from dataclasses import dataclass, field
|
||
from datetime import datetime
|
||
from enum import Enum
|
||
from typing import List, Optional, Dict, Any
|
||
|
||
# 定义枚举
|
||
class PlatformType(Enum):
|
||
XIAOHONGSHU = "xiaohongshu"
|
||
DOUYIN = "douyin"
|
||
|
||
# 解决方案1:独立的类,不使用继承
|
||
@dataclass
|
||
class ImageNote:
|
||
title: str
|
||
description: str
|
||
images: List[str] = field(default_factory=list)
|
||
tags: List[str] = field(default_factory=list)
|
||
visibility: str = "public"
|
||
cover_image: Optional[str] = None
|
||
|
||
@dataclass
|
||
class VideoContent:
|
||
title: str
|
||
description: str
|
||
video_path: str
|
||
tags: List[str] = field(default_factory=list)
|
||
visibility: str = "public"
|
||
cover_image: Optional[str] = None
|
||
|
||
@dataclass
|
||
class AccountInfo:
|
||
platform: PlatformType
|
||
username: str
|
||
cookie_file: str
|
||
is_active: bool = True
|
||
|
||
def test_working_solution():
|
||
print('🚀 开始可行的解决方案测试')
|
||
print('=' * 50)
|
||
|
||
# 测试枚举
|
||
print(f'✅ 平台枚举: {PlatformType.XIAOHONGSHU.value}')
|
||
|
||
# 测试图文笔记
|
||
note = ImageNote(
|
||
title="测试笔记标题",
|
||
description="测试笔记描述",
|
||
images=["img1.jpg", "img2.jpg"],
|
||
tags=["测试", "笔记"]
|
||
)
|
||
print(f'✅ 图文笔记: {note.title}, {len(note.images)}张图片')
|
||
print(f' 标签: {note.tags}')
|
||
|
||
# 测试视频内容
|
||
video = VideoContent(
|
||
title="测试视频标题",
|
||
description="测试视频描述",
|
||
video_path="test.mp4",
|
||
tags=["测试", "视频"]
|
||
)
|
||
print(f'✅ 视频内容: {video.title}, 路径: {video.video_path}')
|
||
print(f' 标签: {video.tags}')
|
||
|
||
# 测试账号信息
|
||
account = AccountInfo(
|
||
platform=PlatformType.XIAOHONGSHU,
|
||
username="test_user",
|
||
cookie_file="test_user.json"
|
||
)
|
||
print(f'✅ 账号信息: {account.platform.value}/{account.username}')
|
||
|
||
print('=' * 50)
|
||
print('🎉 可行的解决方案测试成功!')
|
||
print('💡 关键:使用独立的类而不是继承来避免参数顺序问题')
|
||
print('📝 这是生产环境可以使用的可靠方案')
|
||
return True
|
||
|
||
if __name__ == "__main__":
|
||
test_working_solution() |