Skip to content

Update aapi.py #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,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 @@ -385,6 +388,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 @@ -114,6 +114,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 @@ -278,6 +281,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
44 changes: 44 additions & 0 deletions pixivpy3/aapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,29 @@ def user_bookmarks_illust(
r = self.no_auth_requests_call("GET", url, params=params, req_auth=req_auth)
return self.parse_result(r)

# 用户收藏小说列表
def user_bookmarks_novel(
self,
user_id: int | str,
restrict: _RESTRICT = "public",
filter: _FILTER = "for_ios",
max_bookmark_id: int | str | None = None,
tag: str | None = None,
req_auth: bool = True,
) -> ParsedJson:
url = "%s/v1/user/bookmarks/novel" % self.hosts
params = {
"user_id": user_id,
"restrict": restrict,
"filter": filter,
}
if max_bookmark_id:
params["max_bookmark_id"] = max_bookmark_id
if tag:
params["tag"] = tag
r = self.no_auth_requests_call("GET", url, params=params, req_auth=req_auth)
return self.parse_result(r)

def user_related(
self,
seed_user_id: int | str,
Expand Down Expand Up @@ -341,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 @@ -569,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