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

return None return None


post = 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 sfw:
if post["rating"] == "e" or post["rating"] == "q": if post["rating"] == "e" or post["rating"] == "q":
continue continue
if len(cache[cache_id]) > 10: if len(cache[cache_id]) > 10:
cache[cache_id].pop(0) cache[cache_id].pop(0)
break break
counter += 1
if not posts:
return None


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

Loading…
Cancel
Save