Merge branch 'fixing_danbooru' into 'master'
Fixing the way we retrieve images from danbooru See merge request ldooks/dragon-bot!58
This commit is contained in:
commit
4fec8ea6df
33
app/lewds.py
33
app/lewds.py
@ -10,11 +10,36 @@ def get_from_danbooru(boards):
|
||||
|
||||
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):
|
||||
if 'nsfw' in channel_name:
|
||||
|
Loading…
x
Reference in New Issue
Block a user