forked from upbit/pixivpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
331 lines (271 loc) · 10.6 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
if sys.version_info >= (3, 0):
import imp
imp.reload(sys)
else:
reload(sys)
sys.setdefaultencoding('utf8')
sys.dont_write_bytecode = True
from pixivpy3 import *
## change _USERNAME,_PASSWORD first!
_USERNAME = "usersp"
_PASSWORD = "passsp"
_TEST_WRITE = False
## If a special network environment is met, please configure requests as you need.
## Otherwise, just keep it empty.
_REQUESTS_KWARGS = {
# 'proxies': {
# 'https': 'https://127.0.0.1:8888',
# },
# '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(">>> %s, origin url: %s" % (illust.title, illust.image_urls['large']))
json_result = aapi.illust_comments(59580629)
print(json_result)
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(">>> %s, origin url: %s" % (illust.title, illust.image_urls['large']))
# get next page
next_qs = aapi.parse_qs(json_result.next_url)
json_result = aapi.illust_recommended(**next_qs)
# print(json_result)
illust = json_result.illusts[0]
print(" > %s, origin url: %s" % (illust.title, illust.image_urls['large']))
json_result = aapi.illust_related(59580629)
print(json_result)
illust = json_result.illusts[0]
print(">>> %s, origin url: %s" % (illust.title, illust.image_urls['large']))
# get next page
next_qs = aapi.parse_qs(json_result.next_url)
json_result = aapi.illust_related(**next_qs)
# print(json_result)
illust = json_result.illusts[0]
print(" > %s, origin url: %s" % (illust.title, illust.image_urls['large']))
def appapi_users(aapi):
json_result = aapi.user_detail(275527)
print(json_result)
user = json_result.user
print("%s(@%s) region=%s" % (user.name, user.account, json_result.profile.region))
json_result = aapi.user_illusts(275527)
print(json_result)
illust = json_result.illusts[0]
print(">>> %s, origin url: %s" % (illust.title, illust.image_urls['large']))
# get next page
next_qs = aapi.parse_qs(json_result.next_url)
json_result = aapi.user_illusts(**next_qs)
# print(json_result)
illust = json_result.illusts[0]
print(" > %s, origin url: %s" % (illust.title, illust.image_urls['large']))
json_result = aapi.user_bookmarks_illust(2088434)
print(json_result)
illust = json_result.illusts[0]
print(">>> %s, origin url: %s" % (illust.title, illust.image_urls['large']))
json_result = aapi.user_following(7314824)
print(json_result)
user_preview = json_result.user_previews[0]
print(">>> %s(@%s)" % (user_preview.user.name, user_preview.user.account))
next_qs = aapi.parse_qs(json_result.next_url)
json_result = aapi.user_following(**next_qs)
# print(json_result)
user_preview = json_result.user_previews[0]
print(" > %s(@%s)" % (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)
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("%s - %s(id=%s)" % (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(">>> %s, origin url: %s" % (illust.title, illust.image_urls['large']))
# get next page
next_qs = aapi.parse_qs(json_result.next_url)
json_result = aapi.search_illust(**next_qs)
# print(json_result)
illust = json_result.illusts[0]
print(">>> %s, origin url: %s" % (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(">>> %s, origin url: %s" % (illust.title, illust.image_urls['large']))
# get next page
next_qs = aapi.parse_qs(json_result.next_url)
json_result = aapi.illust_ranking(**next_qs)
# print(json_result)
illust = json_result.illusts[0]
print(">>> %s, origin url: %s" % (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(">>> %s, origin url: %s" % (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(">>> %s, origin url: %s" % (illust.title, illust.image_urls['large']))
# get next page
next_qs = aapi.parse_qs(json_result.next_url)
json_result = aapi.illust_follow(req_auth=True, **next_qs)
# print(json_result)
illust = json_result.illusts[0]
print(">>> %s, origin url: %s" % (illust.title, illust.image_urls['large']))
json_result = aapi.illust_recommended(req_auth=True)
print(json_result)
illust = json_result.illusts[0]
print(">>> %s, origin url: %s" % (illust.title, illust.image_urls['large']))
## PAPI start
def migrate_rev2_to_papi(api):
print(">>> new ranking_all(mode='daily', page=1, per_page=50)")
# rank_list = api.sapi.ranking("all", 'day', 1)
rank_list = api.ranking_all('daily', 1, 50)
print(rank_list)
# more fields about response: https://github.com/upbit/pixivpy/wiki/sniffer
ranking = rank_list.response[0]
for img in ranking.works:
# print img.work
print("[%s/%s(id=%s)] %s" % (img.work.user.name, img.work.title, img.work.id, img.work.image_urls.px_480mw))
def papi_base(api):
# PAPI.works
json_result = api.works(46363414)
print(json_result)
illust = json_result.response[0]
print(">>> %s, origin url: %s" % (illust.caption, illust.image_urls['large']))
# PAPI.users
json_result = api.users(1184799)
print(json_result)
user = json_result.response[0]
print(user.profile.introduction)
def papi_me(api):
# PAPI.me_feeds
json_result = api.me_feeds(show_r18=0)
print(json_result)
# work = json_result.response[0].ref_user.works[0]
# print(work.title)
# PAPI.me_favorite_works
json_result = api.me_favorite_works(publicity='private')
print(json_result)
illust = json_result.response[0].work
print("[%s] %s: %s" % (illust.user.name, illust.title, illust.image_urls.px_480mw))
# PAPI.me_following_works (New -> Follow)
json_result = api.me_following_works()
print(json_result)
illust = json_result.response[0]
print(">>> %s, origin url: %s" % (illust.caption, illust.image_urls['large']))
if _TEST_WRITE:
# PAPI.me_favorite_works_add
json_result = api.me_favorite_works_add(ref_work.id, publicity='private')
print(json_result)
favorite_id = json_result.response[0].id
print(">>> Add favorite illust_id=%s success! favorite_id=%s" % (ref_work.id, favorite_id))
# PAPI.me_favorite_works_delete
# json_result = api.me_favorite_works_delete([favorite_id, ...], publicity='private')
json_result = api.me_favorite_works_delete(favorite_id, publicity='private')
print(json_result)
def papi_me_user(api):
# PAPI.me_following
json_result = api.me_following()
print(json_result)
user = json_result.response[0]
print(user.name)
if _TEST_WRITE:
# PAPI.me_favorite_users_follow
user_id = 1184799
json_result = api.me_favorite_users_follow(user_id)
print(json_result)
user = json_result.response[0].target_user
print(user.name)
# PAPI.me_favorite_users_unfollow
json_result = api.me_favorite_users_unfollow(user_id)
print(json_result)
def papi_user(api):
# PAPI.users_works
json_result = api.users_works(1184799)
print(json_result)
illust = json_result.response[0]
print(">>> %s, origin url: %s" % (illust.caption, illust.image_urls['large']))
# PAPI.users_favorite_works
json_result = api.users_favorite_works(1184799)
print(json_result)
illust = json_result.response[0].work
print(">>> %s origin url: %s" % (illust.caption, illust.image_urls['large']))
# PAPI.users_feeds
json_result = api.users_feeds(1184799, show_r18=0)
print(json_result)
ref_work = json_result.response[0].ref_work
print(ref_work.title)
# PAPI.users_following
json_result = api.users_following(4102577)
print(json_result)
user = json_result.response[0]
print(user.name)
def papi_ranking(api):
# PAPI.ranking
json_result = api.ranking('illust', 'weekly', 1)
print(json_result)
illust = json_result.response[0].works[0].work
print(">>> %s origin url: %s" % (illust.title, illust.image_urls['large']))
# PAPI.ranking(2015-05-01)
json_result = api.ranking(ranking_type='all', mode='daily', page=1, date='2015-05-01')
print(json_result)
illust = json_result.response[0].works[0].work
print(">>> %s origin url: %s" % (illust.title, illust.image_urls['large']))
def papi_search(api):
# PAPI.search_works
json_result = api.search_works("五航戦 姉妹", page=1, mode='text')
# json_result = api.search_works("水遊び", page=1, mode='exact_tag')
print(json_result)
illust = json_result.response[0]
print(">>> %s origin url: %s" % (illust.title, illust.image_urls['large']))
def papi_others(api):
# PAPI.latest_works (New -> Everyone)
json_result = api.latest_works()
print(json_result)
illust = json_result.response[0]
print(">>> %s url: %s" % (illust.title, illust.image_urls.px_480mw))
def old_main():
# public-api
api = PixivAPI(**_REQUESTS_KWARGS)
api.login(_USERNAME, _PASSWORD)
migrate_rev2_to_papi(api)
papi_base(api)
papi_me(api)
papi_me_user(api)
papi_user(api)
papi_ranking(api)
papi_search(api)
papi_others(api)
def main():
# app-api
aapi = AppPixivAPI(**_REQUESTS_KWARGS)
# no auth test
appapi_illust(aapi)
appapi_recommend(aapi)
appapi_users(aapi)
appapi_search(aapi)
appapi_ranking(aapi)
# auth test
aapi.login(_USERNAME, _PASSWORD)
appapi_auth_api(aapi)
if __name__ == '__main__':
main()