Refactored and improved exception handling

This commit is contained in:
Anon 2022-08-30 00:16:50 -07:00
parent 71f321c6f9
commit 2475241f21

View File

@ -9,15 +9,11 @@ import os
def random_tag(*tags):
if len(tags) == 1 and tags[0].lower() == "random":
return True
return False
return len(tags) == 1 and tags[0].lower() == "random"
def get_most_sever_rating(*ratings):
if "q" in ratings or "e" in ratings:
return True
return False
def get_most_sever_rating(rating):
return rating in ("q", "e")
class downloader:
@ -42,8 +38,7 @@ class downloader:
print("Remote image request returned:", remote_image.status_code)
return None
for d in full_path:
with open(d, "wb") as f:
with open(full_path, "wb") as f:
f.write(remote_image.content)
return post
@ -80,7 +75,7 @@ class downloader:
if tag_type in response:
tag_response.append(response[tag_type].strip())
nsfw = search_request.json()[0]["rating"]
nsfw = response["rating"]
nsfw = get_most_sever_rating(nsfw)
file_url = response["file_url"]
@ -99,7 +94,7 @@ class downloader:
# Query results
"search_url": search_url,
"file_url": file_url,
"full_path": [full_path],
"full_path": full_path,
"tag_response": " ".join(tag_response),
"nsfw": nsfw
}