Skip to content
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

feat(enums): add enums #382

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
74 changes: 40 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Requirements: [requests](https://pypi.python.org/pypi/requests)

```python
from pixivpy3 import AppPixivAPI
from pixivpy3 import enums

access_token = "..."
refresh_token = "..."
Expand All @@ -134,7 +135,7 @@ print(f">>> origin url: {illust.image_urls.large}")

# get ranking: 1-30
# mode: [day, week, month, day_male, day_female, week_original, week_rookie, day_manga]
json_result = api.illust_ranking('day')
json_result = api.illust_ranking(mode=enums.RankingMode.DAY)
for illust in json_result.illusts:
print(f" p1 [{illust.title}] {illust.image_urls.medium}")

Expand Down Expand Up @@ -164,6 +165,7 @@ while next_qs:

```python
from pixivpy3 import AppPixivAPI

aapi = AppPixivAPI()
json_result = aapi.illust_ranking()
for illust in json_result.illusts[:3]:
Expand All @@ -176,9 +178,10 @@ for illust in json_result.illusts[:3]:
2. Change deprecated SPAI call to Public-API call

```python
from pixivpy3 import AppPixivAPI
from pixivpy3 import AppPixivAPI, enums

api = AppPixivAPI()
rank_list = api.illust_ranking('day')
rank_list = api.illust_ranking(enums.RankingMode.DAY)
print(rank_list)

# more fields about response: https://github.com/upbit/pixivpy/wiki/sniffer
Expand All @@ -205,8 +208,8 @@ Find Pixiv API in **Objective-C**? You might also like
```python
from __future__ import annotations
from typing import Any
from pixivpy3 import enums
from pixivpy3.utils import ParsedJson

from pixivpy3.api import BasePixivAPI


Expand All @@ -220,20 +223,20 @@ class AppPixivAPI(BasePixivAPI):

# 用户作品列表
## type: [illust, manga]
def user_illusts(self, user_id: int | str, type="illust") -> ParsedJson: ...
def user_illusts(self, user_id: int | str, type=enums.ContentType.ILLUSTRATION) -> ParsedJson: ...

# 用户收藏作品列表
# tag: 从 user_bookmark_tags_illust 获取的收藏标签
def user_bookmarks_illust(self, user_id: int | str, restrict="public") -> ParsedJson: ...
def user_bookmarks_illust(self, user_id: int | str, restrict=enums.Visibility.PUBLIC) -> ParsedJson: ...

# 用户收藏作品列表中的小说
def user_bookmarks_novel(self, user_id: int | str, restrict="public") -> ParsedJson: ...
def user_bookmarks_novel(self, user_id: int | str, restrict=enums.Visibility.PUBLIC) -> ParsedJson: ...

def user_related(self, seed_user_id: int | str) -> ParsedJson: ...

# 关注用户的新作
# restrict: [public, private]
def illust_follow(self, restrict="public") -> ParsedJson: ...
def illust_follow(self, restrict=enums.Visibility.PUBLIC) -> ParsedJson: ...

# 作品详情 (类似PAPI.works(),iOS中未使用)
def illust_detail(self, illust_id: int | str) -> ParsedJson: ...
Expand All @@ -246,7 +249,7 @@ class AppPixivAPI(BasePixivAPI):

# 插画推荐 (Home - Main)
# content_type: [illust, manga]
def illust_recommended(self, content_type="illust") -> ParsedJson: ...
def illust_recommended(self, content_type=enums.ContentType.ILLUSTRATION) -> ParsedJson: ...

# 小说推荐
def novel_recommended(self) -> ParsedJson: ...
Expand All @@ -256,7 +259,7 @@ class AppPixivAPI(BasePixivAPI):
# date: '2016-08-01'
# mode (Past): [day, week, month, day_male, day_female, week_original, week_rookie,
# day_r18, day_male_r18, day_female_r18, week_r18, week_r18g]
def illust_ranking(self, mode="day", date=None) -> ParsedJson: ...
def illust_ranking(self, mode=enums.RankingMode.DAY, date=None) -> ParsedJson: ...

# 趋势标签 (Search - tags)
def trending_tags_illust(self) -> ParsedJson: ...
Expand All @@ -270,13 +273,13 @@ class AppPixivAPI(BasePixivAPI):
# duration: [within_last_day, within_last_week, within_last_month]
# start_date, end_date: '2020-07-01'
def search_illust(
self,
word: str,
search_target="partial_match_for_tags",
sort="date_desc",
duration=None,
start_date=None,
end_date=None,
self,
word: str,
search_target=enums.SearchTarget.PARTIAL_MATCH_FOR_TAGS,
sort=enums.Sort.DATE_DESC,
duration=None,
start_date=None,
end_date=None,
) -> ParsedJson: ...

# 搜索小说 (Search Novel)
Expand All @@ -288,36 +291,36 @@ class AppPixivAPI(BasePixivAPI):
# sort: [date_desc, date_asc]
# start_date/end_date: 2020-06-01
def search_novel(
self,
word: str,
search_target="partial_match_for_tags",
sort="date_desc",
start_date=None,
end_date=None,
self,
word: str,
search_target=enums.SearchTarget.PARTIAL_MATCH_FOR_TAGS,
sort=enums.Sort.DATE_DESC,
start_date=None,
end_date=None,
) -> ParsedJson: ...

def search_user(self, word: str, sort='date_desc', duration=None) -> ParsedJson: ...
def search_user(self, word: str, sort=enums.Sort.DATE_DESC, duration=None) -> ParsedJson: ...

# 作品收藏详情
def illust_bookmark_detail(self, illust_id: int | str) -> ParsedJson: ...

# 新增收藏
def illust_bookmark_add(self, illust_id: int | str, restrict="public", tags=None) -> ParsedJson: ...
def illust_bookmark_add(self, illust_id: int | str, restrict=enums.Visibility.PUBLIC, tags=None) -> ParsedJson: ...

# 删除收藏
def illust_bookmark_delete(self, illust_id: int | str) -> ParsedJson: ...

# 关注用户
def user_follow_add(self, user_id: int | str, restrict="public") -> ParsedJson: ...
def user_follow_add(self, user_id: int | str, restrict=enums.Visibility.PUBLIC) -> ParsedJson: ...

# 取消关注用户
def user_follow_delete(self, user_id: int | str) -> ParsedJson: ...

# 用户收藏标签列表
def user_bookmark_tags_illust(self, restrict="public") -> ParsedJson: ...
def user_bookmark_tags_illust(self, restrict=enums.Visibility.PUBLIC) -> ParsedJson: ...

# Following用户列表
def user_following(self, user_id: int | str, restrict="public") -> ParsedJson: ...
def user_following(self, user_id: int | str, restrict=enums.Visibility.PUBLIC) -> ParsedJson: ...

# Followers用户列表
def user_follower(self, user_id: int | str) -> ParsedJson: ...
Expand Down Expand Up @@ -348,7 +351,7 @@ class AppPixivAPI(BasePixivAPI):

# 大家的新作
# content_type: [illust, manga]
def illust_new(self, content_type="illust", max_illust_id=None) -> ParsedJson: ...
def illust_new(self, content_type=enums.ContentType.ILLUSTRATION, max_illust_id=None) -> ParsedJson: ...

def novel_new(self, max_novel_id=None) -> ParsedJson: ...

Expand All @@ -359,7 +362,8 @@ class AppPixivAPI(BasePixivAPI):
[Usage](https://github.com/upbit/pixivpy/blob/aec177aa7a1979f7ec4c5bbbeed9085cc256bdbd/demo.py#L306):

```python
from pixivpy3 import AppPixivAPI
from pixivpy3 import AppPixivAPI, enums

api = AppPixivAPI()

# 作品推荐
Expand Down Expand Up @@ -406,7 +410,7 @@ novel = json_result.novels[0]
print(f">>> {novel.title}, text_length: {novel.text_length}, series: {novel.series}")

# 2016-07-15 日的过去一周排行
json_result = api.illust_ranking('week', date='2016-07-15')
json_result = api.illust_ranking(enums.RankingMode.WEEK, date='2016-07-15')
print(json_result)
illust = json_result.illusts[0]
print(f">>> {illust.title}, origin url: {illust.image_urls.large}")
Expand All @@ -418,7 +422,7 @@ illust = json_result.illusts[0]
print(f">>> {illust.title}, origin url: {illust.image_urls.large}")

# 标签 "水着" 搜索
json_result = api.search_illust('水着', search_target='partial_match_for_tags')
json_result = api.search_illust('水着', search_target=enums.SearchTarget.PARTIAL_MATCH_FOR_TAGS)
print(json_result)
illust = json_result.illusts[0]
print(f">>> {illust.title}, origin url: {illust.image_urls.large}")
Expand All @@ -434,9 +438,11 @@ json_result = api.novel_comments(16509454, include_total_comments=True)
print(f"Total comments = {json_result.total_comments}")
for comment in json_result.comments:
if comment.parent_comment:
print(f"{comment.user.name} replied to {comment.parent_comment.user.name} at {comment.date} : {comment.comment}")
text = f"{comment.user.name} replied to {comment.parent_comment.user.name} at {comment.date} : {comment.comment}"
print(text)
else:
print(f"{comment.user.name} at {comment.date} : {comment.comment}")
text = f"{comment.user.name} at {comment.date} : {comment.comment}"
print(text)
```

## Package Publishing Instructions
Expand Down
12 changes: 8 additions & 4 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
import time

from pixivpy3 import AppPixivAPI, PixivError
from pixivpy3 import AppPixivAPI, PixivError, enums

sys.dont_write_bytecode = True

Expand Down Expand Up @@ -131,7 +131,7 @@ def appapi_search(aapi):
first_tag = trend_tag.tag
print(f"{trend_tag.tag} - {trend_tag.illust.title}(id={trend_tag.illust.id})")

json_result = aapi.search_illust(first_tag, search_target="partial_match_for_tags")
json_result = aapi.search_illust(first_tag, search_target=enums.SearchTarget.PARTIAL_MATCH_FOR_TAGS)
print(json_result)
illust = json_result.illusts[0]
print(f">>> {illust.title}, origin url: {illust.image_urls.large}")
Expand All @@ -145,7 +145,7 @@ def appapi_search(aapi):
print(f">>> {illust.title}, origin url: {illust.image_urls.large}")

# novel
json_result = aapi.search_novel("FGO", search_target="keyword")
json_result = aapi.search_novel("FGO", search_target=enums.SearchTarget.KEYWORD)
print(json_result)
novel = json_result.novels[0]
print(f">>> {illust.title}, origin url: {illust.image_urls.large}")
Expand All @@ -158,7 +158,11 @@ def appapi_search(aapi):
novel = json_result.novels[0]
print(f">>> {novel.title}, origin url: {novel.image_urls['large']}")

json_result = aapi.search_illust("AI生成", search_target="exact_match_for_tags", search_ai_type=0)
json_result = aapi.search_illust(
"AI生成",
search_target=enums.SearchTarget.EXACT_MATCH_FOR_TAGS,
search_ai_type=0,
)
# 关闭AI搜索选项后,将过滤掉所有illust_ai_type=2的插画,而illust_ai_type=1 or 0 的插画将被保留
# 但是,加入了"AI生成"的tag却没有在作品提交时打开“AI生成”的开关的作品不会被筛选出结果列表
print(json_result.illusts[0])
Expand Down
4 changes: 2 additions & 2 deletions download_illusts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import sys

from pixivpy3 import AppPixivAPI, ByPassSniApi
from pixivpy3 import AppPixivAPI, ByPassSniApi, enums

sys.dont_write_bytecode = True

Expand All @@ -23,7 +23,7 @@ def main():
api.auth(refresh_token=_REFRESH_TOKEN)

# get rankings
json_result = api.illust_ranking("day", date="2019-01-01")
json_result = api.illust_ranking(enums.RankingMode.DAY, date="2019-01-01")

directory = "illusts"
if not os.path.exists(directory):
Expand Down
4 changes: 2 additions & 2 deletions example_bypass_sni.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from datetime import datetime, timedelta

from pixivpy3 import ByPassSniApi
from pixivpy3 import ByPassSniApi, enums

sys.dont_write_bytecode = True

Expand All @@ -21,7 +21,7 @@ def main():
print(api.auth(refresh_token=_REFRESH_TOKEN))
date = datetime.now() - timedelta(days=5)
date_str = date.strftime("%Y-%m-%d")
json_result = api.illust_ranking("day", date=date_str)
json_result = api.illust_ranking(enums.RankingMode.DAY, date=date_str)

print("Printing image titles and tags with English tag translations present when available")

Expand Down
4 changes: 2 additions & 2 deletions example_tag_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
from datetime import datetime, timedelta

from pixivpy3 import AppPixivAPI
from pixivpy3 import AppPixivAPI, enums

sys.dont_write_bytecode = True

Expand All @@ -21,7 +21,7 @@ def main():
aapi.auth(refresh_token=_REFRESH_TOKEN)
date = datetime.now() - timedelta(days=5)
date_str = date.strftime("%Y-%m-%d")
json_result = aapi.illust_ranking("day", date=date_str)
json_result = aapi.illust_ranking(enums.RankingMode.DAY, date=date_str)

print("Printing image titles and tags with English tag translations present when available")

Expand Down
Loading
Loading