-
Notifications
You must be signed in to change notification settings - Fork 147
/
demo.py
343 lines (276 loc) · 11.9 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#!/usr/bin/env python
import sys
import time
from pixivpy3 import AppPixivAPI, PixivError
sys.dont_write_bytecode = True
# get your refresh_token, and replace _REFRESH_TOKEN
# https://github.com/upbit/pixivpy/issues/158#issuecomment-778919084
_REFRESH_TOKEN = "0zeYA-PllRYp1tfrsq_w3vHGU1rPy237JMf5oDt73c4"
_TEST_WRITE = False
# If a special network environment is meet, please configure requests as you need.
# Otherwise, just keep it empty.
_REQUESTS_KWARGS = {
# 'proxies': {
# 'https': 'http://127.0.0.1:1087',
# },
# 'verify': False, # PAPI use https, an easy way is disable requests SSL verify
}
# AppAPI start
def appapi_illust(aapi):
json_result = aapi.illust_detail(59580629)
print(json_result)
illust = json_result.illust
print(">>> {}, origin url: {}".format(illust.title, illust.image_urls["large"]))
json_result = aapi.illust_comments(59580629)
print(json_result)
# (2020/01/28) Comment because 51815717 is deleted
# json_result = aapi.ugoira_metadata(51815717)
# print(json_result)
# metadata = json_result.ugoira_metadata
# print(">>> frames=%d %s" % (len(metadata.frames), metadata.zip_urls.medium))
def appapi_recommend(aapi):
json_result = aapi.illust_recommended(bookmark_illust_ids=[59580629])
print(json_result)
illust = json_result.illusts[0]
print(">>> {}, origin url: {}".format(illust.title, illust.image_urls["large"]))
# get next page
next_qs = aapi.parse_qs(json_result.next_url)
if next_qs is not None:
json_result = aapi.illust_recommended(**next_qs)
# print(json_result)
illust = json_result.illusts[0]
print(" > {}, origin url: {}".format(illust.title, illust.image_urls["large"]))
json_result = aapi.illust_related(59580629)
print(json_result)
illust = json_result.illusts[0]
print(">>> {}, origin url: {}".format(illust.title, illust.image_urls["large"]))
# get next page
next_qs = aapi.parse_qs(json_result.next_url)
if next_qs is not None:
json_result = aapi.illust_related(**next_qs)
# print(json_result)
illust = json_result.illusts[0]
print(" > {}, origin url: {}".format(illust.title, illust.image_urls["large"]))
def appapi_users(aapi):
json_result = aapi.user_detail(275527)
print(json_result)
user = json_result.user
print("{}(@{}) region={}".format(user.name, user.account, json_result.profile.region))
json_result = aapi.user_illusts(275527)
print(json_result)
illust = json_result.illusts[0]
print(">>> {}, origin url: {}".format(illust.title, illust.image_urls["large"]))
# get next page
next_qs = aapi.parse_qs(json_result.next_url)
if next_qs is not None:
json_result = aapi.user_illusts(**next_qs)
# print(json_result)
illust = json_result.illusts[0]
print(" > {}, origin url: {}".format(illust.title, illust.image_urls["large"]))
json_result = aapi.user_bookmarks_illust(2088434)
print(json_result)
illust = json_result.illusts[0]
print(">>> {}, origin url: {}".format(illust.title, illust.image_urls["large"]))
json_result = aapi.user_bookmarks_novel(42862448)
print(json_result)
novel = json_result.novels[0]
print(">>> {}, text_length: {}, series: {}".format(novel.title, novel.text_length, novel.series))
json_result = aapi.user_following(7314824)
print(json_result)
user_preview = json_result.user_previews[0]
print(">>> {}(@{})".format(user_preview.user.name, user_preview.user.account))
next_qs = aapi.parse_qs(json_result.next_url)
if next_qs is not None:
json_result = aapi.user_following(**next_qs)
# print(json_result)
user_preview = json_result.user_previews[0]
print(" > {}(@{})".format(user_preview.user.name, user_preview.user.account))
json_result = aapi.user_follower(275527)
print(json_result)
json_result = aapi.user_mypixiv(275527)
print(json_result)
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
response = aapi.trending_tags_illust()
for trend_tag in response.trend_tags[:10]:
if not first_tag:
first_tag = trend_tag.tag
print("{} - {}(id={})".format(trend_tag.tag, trend_tag.illust.title, trend_tag.illust.id))
json_result = aapi.search_illust(first_tag, search_target="partial_match_for_tags")
print(json_result)
illust = json_result.illusts[0]
print(">>> {}, origin url: {}".format(illust.title, illust.image_urls["large"]))
# get next page
next_qs = aapi.parse_qs(json_result.next_url)
if next_qs is not None:
json_result = aapi.search_illust(**next_qs)
# print(json_result)
illust = json_result.illusts[0]
print(">>> {}, origin url: {}".format(illust.title, illust.image_urls["large"]))
# novel
json_result = aapi.search_novel("FGO", search_target="keyword")
print(json_result)
novel = json_result.novels[0]
print(">>> {}, origin url: {}".format(novel.title, novel.image_urls["large"]))
# get next page
next_qs = aapi.parse_qs(json_result.next_url)
if next_qs is not None:
json_result = aapi.search_novel(**next_qs)
# print(json_result)
novel = json_result.novels[0]
print(">>> {}, origin url: {}".format(novel.title, novel.image_urls["large"]))
json_result = aapi.search_illust("AI生成", search_target="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])
def appapi_user_search(aapi):
json_result = aapi.illust_ranking("day_male")
name = json_result.illusts[0].user.name
print(">>> %s" % name)
json_result = aapi.search_user(name)
print(json_result)
illust = json_result.user_previews[0].illusts[0]
print(">>> {}, origin url: {}".format(illust.title, illust.image_urls["large"]))
# get next page
next_qs = aapi.parse_qs(json_result.next_url)
if next_qs is not None:
json_result = aapi.search_user(**next_qs)
# print(json_result)
illust = json_result.user_previews[0].illusts[0]
print(">>> {}, origin url: {}".format(illust.title, illust.image_urls["large"]))
def appapi_ranking(aapi):
json_result = aapi.illust_ranking("day_male")
print(json_result)
illust = json_result.illusts[0]
print(">>> {}, origin url: {}".format(illust.title, illust.image_urls["large"]))
# get next page
next_qs = aapi.parse_qs(json_result.next_url)
if next_qs is not None:
json_result = aapi.illust_ranking(**next_qs)
# print(json_result)
illust = json_result.illusts[0]
print(">>> {}, origin url: {}".format(illust.title, illust.image_urls["large"]))
# 2016-07-15 日的过去一周排行
json_result = aapi.illust_ranking("week", date="2016-07-15")
print(json_result)
illust = json_result.illusts[0]
print(">>> {}, origin url: {}".format(illust.title, illust.image_urls["large"]))
def appapi_auth_api(aapi):
json_result = aapi.illust_follow(req_auth=True)
print(json_result)
illust = json_result.illusts[0]
print(">>> {}, origin url: {}".format(illust.title, illust.image_urls["large"]))
# get next page
next_qs = aapi.parse_qs(json_result.next_url)
if next_qs is not None:
json_result = aapi.illust_follow(req_auth=True, **next_qs)
# print(json_result)
illust = json_result.illusts[0]
print(">>> {}, origin url: {}".format(illust.title, illust.image_urls["large"]))
json_result = aapi.illust_recommended(req_auth=True)
print(json_result)
illust = json_result.illusts[0]
print(">>> {}, origin url: {}".format(illust.title, illust.image_urls["large"]))
def appapi_bookmark_add(aapi):
illust_id = 74187223
tags = ["Fate/GO", "50000users入り", "私服"]
json_result = aapi.illust_bookmark_add(illust_id, tags=tags)
json_result = aapi.illust_bookmark_detail(illust_id)
print(json_result.bookmark_detail)
print(
">>> %s, tags added: %s"
% (
illust_id,
[tag.name for tag in json_result.bookmark_detail.tags if tag.is_registered],
)
)
def appapi_novel(aapi):
json_result = aapi.novel_recommended()
print(json_result)
novel = json_result.novels[0]
print(">>> {}, text_length: {}, series: {}".format(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(">>> {}, text_length: {}, series: {}".format(novel.title, novel.text_length, novel.series))
json_result = aapi.user_novels(59216290)
print(json_result)
novel = json_result.novels[0]
print(">>> {}, text_length: {}, series: {}".format(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.user_novels(**next_qs)
novel = json_result.novels[0]
print(">>> {}, text_length: {}, series: {}".format(novel.title, novel.text_length, novel.series))
json_result = aapi.novel_series(1206600)
print(json_result)
detail = json_result.novel_series_detail
print(">>> {}, total_character_count: {}".format(detail.title, detail.total_character_count))
# get next page
next_qs = aapi.parse_qs(json_result.next_url)
if next_qs is not None:
json_result = aapi.novel_series(**next_qs)
detail = json_result.novel_series_detail
print(">>> {}, total_character_count: {}".format(detail.title, detail.total_character_count))
novel_id = 12438689
json_result = aapi.novel_detail(novel_id)
print(json_result)
novel = json_result.novel
print(">>> {}, text_length: {}, series: {}".format(novel.title, novel.text_length, novel.series))
json_result = aapi.novel_text(novel_id)
print(json_result)
print(">>> {}, novel_text: {}".format(novel.title, json_result.novel_text))
json_result = aapi.novel_follow()
print(json_result)
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
aapi = AppPixivAPI(**_REQUESTS_KWARGS)
_e = None
for _ in range(3):
try:
aapi.auth(refresh_token=_REFRESH_TOKEN)
break
except PixivError as e:
_e = e
time.sleep(10)
else: # failed 3 times
raise _e
appapi_illust(aapi)
appapi_recommend(aapi)
appapi_users(aapi)
appapi_search(aapi)
appapi_user_search(aapi)
appapi_ranking(aapi)
appapi_bookmark_add(aapi)
appapi_novel(aapi)
appapi_auth_api(aapi)
if __name__ == "__main__":
main()