Fixing the way we retrieve images from danbooru

This commit is contained in:
Luke Robles 2018-03-07 12:49:08 -08:00
parent f9ead69f04
commit 9a530ba0b7

View File

@ -10,11 +10,36 @@ def get_from_danbooru(boards):
returns a URL to an image on danbooru returns a URL to an image on danbooru
""" """
file_path = requests.get(
'https://danbooru.donmai.us/posts/random.json?tags=rating%3Aexplicit'
).json()['large_file_url']
return "https://danbooru.donmai.us{}".format(file_path) request = requests.get(
'https://danbooru.donmai.us/posts/random.json?tags=rating%3Aexplicit'
).json()
# List of tags we dont want images from
undesired_tags = [
'bestiality',
'pee',
'futa',
'futanari',
'yaoi'
]
# If any undesired tags show up in the request, try again
if not set(request['tag_string'].split()).isdisjoint(undesired_tags):
return get_from_danbooru(boards)
# Return the large firl url if available
if 'large_file_url' in request.keys():
if request['large_file_url'].startswith('/data/'):
return "https://danbooru.donmai.us{}".format(request['large_file_url'])
return request['large_file_url']
if 'file_url' in request.keys():
if request['file_url'].startswith('/data/'):
return "https://danbooru.donmai.us{}".format(request['file_url'])
return request['file_url']
return get_from_danbooru(boards)
def get_lewd(channel_name): def get_lewd(channel_name):
if 'nsfw' in channel_name: if 'nsfw' in channel_name: