Skip to content

Instantly share code, notes, and snippets.

@20chan
Created February 17, 2017 17:52
Show Gist options
  • Save 20chan/96dc74d9217319df8a4a5639f086b10a to your computer and use it in GitHub Desktop.
Save 20chan/96dc74d9217319df8a4a5639f086b10a to your computer and use it in GitHub Desktop.
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