eink-display/rpi/fetch_image.py

26 lines
621 B
Python

import requests
from dotenv import load_dotenv
import os
load_dotenv()
def fetch_image():
api_url = os.getenv("IMG_HOST_URL")
try:
response = requests.get(api_url)
if response.status_code == 200:
image_data = response.content
with open("image.png", "wb") as file:
file.write(image_data)
print("Image saved successfully as image.png")
else:
print(f"Failed to fetch image: {response.status_code}")
except Exception as e:
print(f"An error occurred: {e}")
fetch_image()