From 68847dc54f41a3c6155c80b4195066c1816eaa24 Mon Sep 17 00:00:00 2001 From: l0tk3 <1037730299@qq.com> Date: Tue, 16 Jul 2024 13:45:12 +0800 Subject: [PATCH] add 'commit' function --- media_platform/xhs/client.py | 10 ++++++++++ media_platform/xhs/core.py | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/media_platform/xhs/client.py b/media_platform/xhs/client.py index c57a51f..5f770b5 100644 --- a/media_platform/xhs/client.py +++ b/media_platform/xhs/client.py @@ -341,6 +341,16 @@ class XiaoHongShuClient(AbstractApiClient): explore_id.append(id) return explore_id + async def commit_note(self, note_oid: str, content: str, at_users: list) -> Dict: + uri = "/api/sns/web/v1/comment/post" + data = { + "note_id": note_oid, + "content": content, + "at_users": at_users + } + #at_users: {"user_id":"6157c0f1000000000201d0d2","nickname":"小红薯6158C511"} + return await self.post(uri, data) + async def like_note(self, note_oid: str) -> Dict: uri = "/api/sns/web/v1/note/like" data = { diff --git a/media_platform/xhs/core.py b/media_platform/xhs/core.py index 6c5a797..fb15eb2 100644 --- a/media_platform/xhs/core.py +++ b/media_platform/xhs/core.py @@ -84,7 +84,7 @@ class XiaoHongShuCrawler(AbstractCrawler): elif config.CRAWLER_TYPE == "explore": await self.get_explore() elif config.CRAWLER_TYPE == "test": - await self.like() + await self.commit() else: pass @@ -132,6 +132,11 @@ class XiaoHongShuCrawler(AbstractCrawler): except DataFetchError: utils.logger.error("[XiaoHongShuCrawler.search] Get note detail error") break + async def commit(self) -> None: + note_id = "66430c5f000000001e01ed41" + ret_v = await self.xhs_client.commit_note(note_id, "你好👋", []) + print(ret_v) + async def like(self) -> None: note_oid = "65f54b1c0000000012022342" ret_v = await self.xhs_client.like_note(note_oid)