Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
VyvaHart committed May 24, 2024
1 parent 1c08368 commit 30ae769
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
Binary file added generated_images/1716567387.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 25 additions & 27 deletions get_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,33 @@ def image_gen():
return None


# def save_image_from_url(file_path):
# try:
# api_response = image_gen()
# url = api_response['data'][0]['url']
def save_image_from_url(file_path):
try:
api_response = image_gen()
url = api_response['data'][0]['url']

# # Send a GET request to the URL
# response_url = requests.get(url)
# # Check if the request was successful
# response_url.raise_for_status()
# Send a GET request to the URL
response_url = requests.get(url)
# Check if the request was successful
response_url.raise_for_status()

# # Open the image from the response content
# image = Image.open(BytesIO(response_url.content))
# Open the image from the response content
image = Image.open(BytesIO(response_url.content))

# # Save the image to the specified file path
# image.save(f"{file_path}" + f"{api_response['created']}.png")
# print(f"Image saved to {file_path}")
# except AttributeError:
# if api_response is None:
# print("api_response variable is None. Cannot perform operation.")
# else:
# print("AttributeError occurred.")
# except requests.exceptions.RequestException as e:
# print(f"Error downloading image: {e}")
# except IOError as e:
# print(f"Error saving image: {e}")
# Save the image to the specified file path
image.save(f"{file_path}" + f"{api_response['created']}.png")
print(f"Image saved to {file_path}")
except AttributeError:
if api_response is None:
print("api_response variable is None. Cannot perform operation.")
else:
print("AttributeError occurred.")
except requests.exceptions.RequestException as e:
print(f"Error downloading image: {e}")
except IOError as e:
print(f"Error saving image: {e}")

# def run():
# save_image_from_url(FILE_PATH)
def run():
save_image_from_url(FILE_PATH)

# run()

print(image_gen())
run()

0 comments on commit 30ae769

Please sign in to comment.