Skip to content

Commit

Permalink
feat: Add novel_recommended() for #248 (#249)
Browse files Browse the repository at this point in the history
upbit authored Sep 10, 2022
1 parent 304e65e commit e5c7062
Showing 3 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -192,6 +192,9 @@ class AppPixivAPI(BasePixivAPI):
# content_type: [illust, manga]
def illust_recommended(content_type="illust"):

# 小说推荐
def novel_recommended():

# 作品排行
# mode: [day, week, month, day_male, day_female, week_original, week_rookie, day_manga]
# date: '2016-08-01'
18 changes: 18 additions & 0 deletions demo.py
Original file line number Diff line number Diff line change
@@ -233,6 +233,24 @@ def appapi_bookmark_add(aapi):


def appapi_novel(aapi):
json_result = aapi.novel_recommended()
print(json_result)
novel = json_result.novels[0]
print(
">>> %s, text_length: %s, series: %s"
% (novel.title, novel.text_length, novel.series)
)

# get next page
next_qs = aapi.parse_qs(json_result.next_url)
if next_qs is not None:
json_result = aapi.novel_recommended(**next_qs)
novel = json_result.novels[0]
print(
">>> %s, text_length: %s, series: %s"
% (novel.title, novel.text_length, novel.series)
)

json_result = aapi.user_novels(59216290)
print(json_result)
novel = json_result.novels[0]
36 changes: 36 additions & 0 deletions pixivpy3/aapi.py
Original file line number Diff line number Diff line change
@@ -330,6 +330,42 @@ def illust_recommended(
r = self.no_auth_requests_call("GET", url, params=params, req_auth=req_auth)
return self.parse_result(r)

# 小说推荐
def novel_recommended(
self,
include_ranking_label: bool | str = True,
filter: _FILTER = "for_ios",
offset: int | str | None = None,
include_ranking_novels: str | bool | None = None,
already_recommended: str | list[str] | None = None,
max_bookmark_id_for_recommend: int | str | None = None,
include_privacy_policy: str | list[int | str] | None = None,
req_auth: bool = True,
) -> ParsedJson:
url = "%s/v1/novel/recommended" % self.hosts
params: dict[str, Any] = {
"include_ranking_label": self.format_bool(include_ranking_label),
"filter": filter,
}
if offset:
params["offset"] = offset
if include_ranking_novels:
params["include_ranking_novels"] = self.format_bool(include_ranking_novels)
if max_bookmark_id_for_recommend:
params["max_bookmark_id_for_recommend"] = max_bookmark_id_for_recommend
if already_recommended:
if isinstance(already_recommended, str):
params["already_recommended"] = already_recommended
elif isinstance(already_recommended, list):
params["already_recommended"] = ",".join(
str(iid) for iid in already_recommended
)
if include_privacy_policy:
params["include_privacy_policy"] = include_privacy_policy

r = self.no_auth_requests_call("GET", url, params=params, req_auth=req_auth)
return self.parse_result(r)

# 作品排行
# mode: [day, week, month, day_male, day_female, week_original, week_rookie, day_manga]
# date: '2016-08-01'

0 comments on commit e5c7062

Please sign in to comment.