-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename download(filename -> path), add download demo for rankings
- Loading branch information
Showing
2 changed files
with
46 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
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 * | ||
|
||
_REQUESTS_KWARGS = { | ||
# 'proxies': { | ||
# 'https': 'http://127.0.0.1:8888', | ||
# }, | ||
# 'verify': False, # PAPI use https, an easy way is disable requests SSL verify | ||
} | ||
|
||
def main(): | ||
aapi = AppPixivAPI(**_REQUESTS_KWARGS) | ||
json_result = aapi.illust_ranking('day', date='2016-08-01') | ||
|
||
directory = "dl" | ||
if not os.path.exists(directory): | ||
os.makedirs(directory) | ||
|
||
# download top3 day rankings to 'dl' dir | ||
for illust in json_result.illusts[:3]: | ||
image_url = illust.meta_single_page.get('original_image_url', illust.image_urls.large) | ||
print("%s: %s" % (illust.title, image_url)) | ||
|
||
filename = os.path.basename(image_url) | ||
extension = os.path.splitext(filename)[1] | ||
path = os.path.join(directory, "illust_id_%d_%s%s" % (illust.id, illust.title, extension)) | ||
aapi.download(illust.image_urls.large, path=path) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters