From f881e5ad9c743ddc9bb63bc6a37ff6ba0df9ac4f Mon Sep 17 00:00:00 2001 From: Zhou Hao Date: Sun, 17 May 2015 22:39:30 +0800 Subject: [PATCH] New papi.users_works instead of sapi.get_member --- README.md | 15 +++++++++------ pixivpy2/papi.py | 43 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 11ec8f13..f3a85e72 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,13 @@ class Pixiv_PAPI(object): # 我的订阅 def me_feeds(self, show_r18=1): + # 用户作品 + # publicity: public, private + def users_works(self, author_id, page=1, per_page=30, publicity='public'): + # 用户收藏 - def users_favorite_works(self, author_id, page=1, per_page=30): + # publicity: public, private + def users_favorite_works(self, author_id, page=1, per_page=30, publicity='public'): # 排行榜/过去排行榜 # mode: @@ -77,10 +82,7 @@ class Pixiv_PAPI(object): # r18g # page: 1-n # date: '2015-04-01' (仅过去排行榜) - def ranking_all(self, mode='daily', page=1, per_page=50, date=None, - image_sizes=['px_128x128', 'px_480mw', 'large'], - profile_image_sizes=['px_170x170', 'px_50x50'], - include_stats=True, include_sanity_level=True): + def ranking_all(self, mode='daily', page=1, per_page=50, date=None): ~~~~~ ### SAPI @@ -113,8 +115,9 @@ class Pixiv_SAPI(object): @deprecated def get_illust(self, illust_id, require_auth=False): - # 用户作品列表 + # 用户作品列表 (新版客户端已使用 PAPI/users_works 代替) # id: author id + @deprecated def get_member(self, id, p=1): # [需鉴权]用户收藏 (新版客户端已使用 PAPI/users/favorite_works 代替) diff --git a/pixivpy2/papi.py b/pixivpy2/papi.py index 30a92b19..5b56624c 100644 --- a/pixivpy2/papi.py +++ b/pixivpy2/papi.py @@ -72,7 +72,6 @@ def me_feeds(self, show_r18=1): url = 'https://public-api.secure.pixiv.net/v1/me/feeds.json' headers = { 'Authorization': 'Bearer %s' % self.api.access_token, - 'Cookie': 'PHPSESSID=%s' % self.api.session, } params = { 'relation': 'all', @@ -83,23 +82,50 @@ def me_feeds(self, show_r18=1): r = self.api._requests_call('GET', url, headers=headers, params=params) return self.parse_result(r) + # 用户作品列表 + # publicity: public, private + def users_works(self, author_id, page=1, per_page=30, publicity='public', + image_sizes=['px_128x128', 'px_480mw', 'large'], + profile_image_sizes=['px_170x170', 'px_50x50'], + include_stats=True, include_sanity_level=True): + self.api._require_auth() + + url = 'https://public-api.secure.pixiv.net/v1/users/%d/works.json' % (author_id) + headers = { + 'Authorization': 'Bearer %s' % self.api.access_token, + } + params = { + 'page': page, + 'per_page': per_page, + 'publicity': publicity, + 'include_stats': include_stats, + 'include_sanity_level': include_sanity_level, + 'image_sizes': ','.join(image_sizes), + 'profile_image_sizes': ','.join(profile_image_sizes), + } + r = self.api._requests_call('GET', url, headers=headers, params=params) + return self.parse_result(r) + # 用户收藏 - def users_favorite_works(self, author_id, page=1, per_page=30): + # publicity: public, private + def users_favorite_works(self, author_id, page=1, per_page=30, publicity='public', + image_sizes=['px_128x128', 'px_480mw', 'large'], + profile_image_sizes=['px_170x170', 'px_50x50'], + include_stats=True, include_sanity_level=True): self.api._require_auth() url = 'https://public-api.secure.pixiv.net/v1/users/%d/favorite_works.json' % (author_id) headers = { 'Authorization': 'Bearer %s' % self.api.access_token, - 'Cookie': 'PHPSESSID=%s' % self.api.session, } params = { 'page': page, 'per_page': per_page, - 'publicity': 'public', # public or private - 'include_work': 'true', - 'include_stats': 'true', - 'image_sizes': 'px_128x128,small,medium,large,px_480mw', - 'profile_image_sizes': 'px_170x170,px_50x50', + 'publicity': publicity, + 'include_stats': include_stats, + 'include_sanity_level': include_sanity_level, + 'image_sizes': ','.join(image_sizes), + 'profile_image_sizes': ','.join(profile_image_sizes), } r = self.api._requests_call('GET', url, headers=headers, params=params) @@ -118,7 +144,6 @@ def ranking_all(self, mode='daily', page=1, per_page=50, date=None, url = 'https://public-api.secure.pixiv.net/v1/ranking/all' headers = { 'Authorization': 'Bearer %s' % self.api.access_token, - 'Cookie': 'PHPSESSID=%s' % self.api.session, } params = { 'mode': mode,