Created
February 17, 2017 17:52
-
-
Save 20chan/96dc74d9217319df8a4a5639f086b10a to your computer and use it in GitHub Desktop.
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
from danbooru import pages | |
from PIL import Image | |
import requests | |
from io import BytesIO | |
def get(size=(300, 300)) : | |
''':returns PIL.Image, 0~2 raiting level. 0 is safe, 1 is questionable, 2 is explicit.''' | |
p = pages(limit=100) | |
while True: | |
post = next(p) | |
if 'file_url' in post.keys(): | |
response = requests.get('https://danbooru.donmai.us{}'.format(post['file_url'])) | |
img = Image.open(BytesIO(response.content)) | |
img = img.resize(size, Image.ANTIALIAS) | |
loc = '{}\\{}.png'.format('sqe'.index(post['rating']), post['id']) | |
print('downloading {}'.format(loc)) | |
img.save(loc) | |
get() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment