smart-interactive-display/Assets/StreamingAssets/MergeFace/test.py

21 lines
582 B
Python
Raw Normal View History

2024-06-27 01:08:10 -07:00
import requests
2024-06-28 01:19:00 -07:00
import os
2024-06-21 01:20:01 -07:00
2024-06-28 01:19:00 -07:00
image_url = "https://i.ibb.co/8Xw8Yhs/4c91e57ac0340d5eaf137cfc48ecb8bc-1557153402.jpg"
2024-06-27 01:08:10 -07:00
2024-06-28 01:19:00 -07:00
file_name = "downloaded_image.jpg"
2024-06-27 01:08:10 -07:00
2024-06-28 01:19:00 -07:00
# Check if the file already exists
if not os.path.exists(file_name):
# Send a GET request to the URL
response = requests.get(image_url)
2024-06-27 01:08:10 -07:00
2024-06-28 01:19:00 -07:00
# Open a local file with write-binary mode
with open(file_name, "wb") as file:
# Write the contents of the response to the file
file.write(response.content)
2024-06-27 01:08:10 -07:00
2024-06-28 01:19:00 -07:00
print(f"Image downloaded and saved as {file_name}")
else:
print(f"{file_name} already exists.")