feat:小红书支持获取评论中的图片链接 #145

This commit is contained in:
Relakkes 2024-03-07 22:30:44 +08:00
parent 861019022a
commit 41fee4ff4f
3 changed files with 14 additions and 6 deletions

View File

@ -267,7 +267,9 @@ class XHSClient:
uri = "/api/sns/web/v2/comment/page"
params = {
"note_id": note_id,
"cursor": cursor
"cursor": cursor,
"top_comment_id":"",
"image_formats": "jpg,webp,avif"
}
return await self.get(uri, params)

View File

@ -63,15 +63,18 @@ async def update_xhs_note(note_item: Dict):
utils.logger.info(f"[store.xhs.update_xhs_note] xhs note: {local_db_item}")
await XhsStoreFactory.create_store().store_content(local_db_item)
async def batch_update_xhs_note_comments(note_id: str, comments: List[Dict]):
if not comments:
return
for comment_item in comments:
await update_xhs_note_comment(note_id, comment_item)
async def update_xhs_note_comment(note_id: str, comment_item: Dict):
user_info = comment_item.get("user_info", {})
comment_id = comment_item.get("id")
comment_pictures = [item.get("url_default", "") for item in comment_item.get("pictures", [])]
local_db_item = {
"comment_id": comment_id,
"create_time": comment_item.get("create_time"),
@ -82,11 +85,13 @@ async def update_xhs_note_comment(note_id: str, comment_item: Dict):
"nickname": user_info.get("nickname"),
"avatar": user_info.get("image"),
"sub_comment_count": comment_item.get("sub_comment_count"),
"pictures": ",".join(comment_pictures),
"last_modify_ts": utils.get_current_timestamp(),
}
utils.logger.info(f"[store.xhs.update_xhs_note_comment] xhs note comment:{local_db_item}")
await XhsStoreFactory.create_store().store_comment(local_db_item)
async def save_creator(user_id: str, creator: Dict):
user_info = creator.get('basicInfo', {})

View File

@ -50,6 +50,7 @@ class XHSNoteComment(XhsBaseModel):
note_id = fields.CharField(max_length=64, description="笔记ID")
content = fields.TextField(description="评论内容")
sub_comment_count = fields.IntField(description="子评论数量")
pictures = fields.CharField(null=True, max_length=512, description="评论的图片集合")
class Meta:
table = "xhs_note_comment"