Skip to content

Commit

Permalink
Add novel_comments() and user_bookmarks_novel() methods
Browse files Browse the repository at this point in the history
* Update aapi.py

Added novel_comments()

* Update aapi.py

* Update README.md

增加对novel_comments()的描述

* Update demo.py

添加对novel_comments()的测试

* Update aapi.py

增加user_bookmarks_novel方法

* Update demo.py

修复了之前自己代码的缩进问题...

* Update aapi.py

与pixivpy3/aapi.py对齐

* Update aapi.py

向user_bookmark_tags_illust加入user_id参数

* Update demo.py

在示例中新增user_bookmark_tags_illust方法的使用

* Update demo.py

重新格式化自己这部分的代码

* Update demo.py

重新格式化代码

* Update demo.py

代码格式化
  • Loading branch information
xiyihan0 authored Dec 11, 2023
1 parent da45c51 commit 40defb0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions pixivpy3/aapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 40defb0

Please sign in to comment.