diff --git a/README.md b/README.md index f08254a..163aa9c 100644 --- a/README.md +++ b/README.md @@ -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' diff --git a/demo.py b/demo.py index 078793a..e5921f2 100644 --- a/demo.py +++ b/demo.py @@ -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] diff --git a/pixivpy3/aapi.py b/pixivpy3/aapi.py index 058129d..64839fa 100644 --- a/pixivpy3/aapi.py +++ b/pixivpy3/aapi.py @@ -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'