diff --git a/README.md b/README.md index 3490473..82956bd 100644 --- a/README.md +++ b/README.md @@ -313,6 +313,9 @@ class AppPixivAPI(BasePixivAPI): # 小说正文 def novel_text(novel_id): + # 小说评论 + def novel_comments(novel_id): + # 大家的新作 # content_type: [illust, manga] def illust_new(content_type="illust", max_illust_id=None): @@ -394,6 +397,15 @@ json_result = aapi.search_user("gomzi") print(json_result) illust = json_result.user_previews[0].illusts[0] print(">>> %s, origin url: %s" % (illust.title, illust.image_urls['large'])) + +# 展示小说评论区 +json_result = aapi.novel_comments(16509454, include_total_comments=True) +print("Total comments = {}".format(json_result["total_comments"])) +for comment in json_result["comments"]: + if comment["parent_comment"] != dict(): + print("{user} replied to {target} at {time} : {content}".format(user = comment["user"]["name"], time = comment["date"], content = comment["comment"], target = comment["parent_comment"]["user"]["name"])) + else: + print("{user} at {time} : {content}".format(user=comment["user"]["name"], time=comment["date"], content=comment["comment"])) ``` ## Package Publishing Instructions diff --git a/demo.py b/demo.py index 29a9f85..e78f6b1 100644 --- a/demo.py +++ b/demo.py @@ -119,6 +119,9 @@ def appapi_users(aapi): json_result = aapi.user_related(275527) print(json_result) + json_result = aapi.user_bookmark_tags_illust(9373351) + print(json_result) + def appapi_search(aapi): first_tag = None @@ -283,6 +286,26 @@ def appapi_novel(aapi): novel = json_result.novels[0] print(">>> {}, text_length: {}, series: {}".format(novel.title, novel.text_length, novel.series)) + # List the comments of the novel + json_result = aapi.novel_comments(16509454, include_total_comments=True) + print("Total comments = {}".format(json_result["total_comments"])) + for comment in json_result["comments"]: + if comment["parent_comment"]: + print( + "{user} replied to {target} at {time} : {content}".format( + user=comment["user"]["name"], + time=comment["date"], + content=comment["comment"], + target=comment["parent_comment"]["user"]["name"], + ) + ) + else: + print( + "{user} at {time} : {content}".format( + user=comment["user"]["name"], time=comment["date"], content=comment["comment"] + ) + ) + def main(): # app-api diff --git a/pixivpy3/aapi.py b/pixivpy3/aapi.py index f7fa0dc..c8fd699 100644 --- a/pixivpy3/aapi.py +++ b/pixivpy3/aapi.py @@ -364,6 +364,25 @@ def illust_recommended( r = self.no_auth_requests_call("GET", url, params=params, req_auth=req_auth) return self.parse_result(r) + # 小说作品评论 + def novel_comments( + self, + novel_id: int | str, + offset: int | str | None = None, + include_total_comments: str | bool | None = None, + req_auth: bool = True, + ) -> ParsedJson: + url = "%s/v1/novel/comments" % self.hosts + params = { + "novel_id": novel_id, + } + if offset: + params["offset"] = offset + if include_total_comments: + params["include_total_comments"] = self.format_bool(include_total_comments) + r = self.no_auth_requests_call("GET", url, params=params, req_auth=req_auth) + return self.parse_result(r) + # 小说推荐 def novel_recommended( self, @@ -592,12 +611,14 @@ def user_follow_delete(self, user_id: int | str, req_auth: bool = True) -> Parse # 用户收藏标签列表 def user_bookmark_tags_illust( self, + user_id: int | str, restrict: _RESTRICT = "public", offset: int | str | None = None, req_auth: bool = True, ) -> ParsedJson: url = "%s/v1/user/bookmark-tags/illust" % self.hosts params: dict[str, Any] = { + "user_id": user_id, "restrict": restrict, } if offset: