Files
Ubuntu 32b43f85bd a
2026-07-03 16:58:28 +08:00

67 lines
1.7 KiB
Python

#!/usr/bin/env python3
"""
发布适配器模块
封装IT资讯项目的共享发布功能
"""
from shared_utils import get_xiaohongshu_publisher
from typing import List, Optional
class XHSPublisherAdapter:
"""小红书发布适配器"""
def __init__(self):
self.PublisherClass = get_xiaohongshu_publisher()
self.publisher = None
def publish(self,
title: str,
content: str,
tags: List[str],
style: str = "tech") -> bool:
"""
发布笔记到小红书
Args:
title: 笔记标题
content: 笔记正文
tags: 话题标签列表
style: 图片风格 (tech/warm/business)
Returns:
是否发布成功
"""
try:
# 初始化发布器
if not self.publisher:
self.publisher = self.PublisherClass()
# 调用共享发布模块
success = self.publisher.publish_to_xiaohongshu(
title=title,
content=content,
tags=tags,
style=style
)
return success
except Exception as e:
print(f"发布失败: {e}")
return False
def get_last_note_id(self) -> Optional[str]:
"""获取最新发布的笔记ID"""
try:
# 从日志或返回信息中获取
# 这里简化处理
return None
except:
return None
if __name__ == "__main__":
# 测试
adapter = XHSPublisherAdapter()
print("发布适配器初始化成功")