Refactored and improved exception handling
This commit is contained in:
parent
71f321c6f9
commit
2475241f21
@ -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,9 +38,8 @@ class downloader:
|
||||
print("Remote image request returned:", remote_image.status_code)
|
||||
return None
|
||||
|
||||
for d in full_path:
|
||||
with open(d, "wb") as f:
|
||||
f.write(remote_image.content)
|
||||
with open(full_path, "wb") as f:
|
||||
f.write(remote_image.content)
|
||||
|
||||
return post
|
||||
|
||||
@ -80,11 +75,11 @@ 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"]
|
||||
|
||||
|
||||
basename = file_url.rsplit("/", 1)[1]
|
||||
full_path = os.path.join(self.tmp, basename)
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user