Browse Source

improved danbooru loop to go the full length of the posts till a good post can be found.

tags/v2.1.0
Roxie Gibson 5 years ago
parent
commit
f7e20197f7
1 changed files with 5 additions and 4 deletions
  1. +5
    -4
      roxbot/utils.py

+ 5
- 4
roxbot/utils.py View File

@@ -227,9 +227,9 @@ async def danbooru_clone_api_req(channel, base_url, endpoint_url, cache=None, ta
return None

post = None
counter = 0
while counter < 50:
post = random.choice(posts)
while posts:
index = random.randint(0, len(posts)-1)
post = posts.pop(index)
if sfw:
if post["rating"] == "e" or post["rating"] == "q":
continue
@@ -239,7 +239,8 @@ async def danbooru_clone_api_req(channel, base_url, endpoint_url, cache=None, ta
if len(cache[cache_id]) > 10:
cache[cache_id].pop(0)
break
counter += 1
if not posts:
return None

url = post.get("file_url")
if not url:

Loading…
Cancel
Save