commit f98fc419fda1e3835461f228eb5c46b04ad4e881 Author: lucaspalomodevelop Date: Sun Mar 31 22:26:16 2024 +0200 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f5e96db --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +venv \ No newline at end of file diff --git a/cron b/cron new file mode 100644 index 0000000..b287828 --- /dev/null +++ b/cron @@ -0,0 +1 @@ +0 0 * * * /usr/bin/python3 /pfad/zu/Ihrem/skript.py \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..7bf84e1 --- /dev/null +++ b/main.py @@ -0,0 +1,69 @@ +import requests +import os +import subprocess +import re + + +# Function to get the URL of Bing's image of the day. +def get_bing_image_of_the_day_url(): + bing_api_url = ( + "http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US" + ) + response = requests.get(bing_api_url) + response.raise_for_status() + image_info = response.json()["images"][0] + image_url = "http://www.bing.com" + image_info["url"] + return image_url + + +# Function to download and save the image to the current directory. +def download_image(image_url, image_path): + response = requests.get(image_url) + response.raise_for_status() + with open(image_path, "wb") as file: + file.write(response.content) + print(f"Image saved as {image_path}") + + +# Function to set the image as desktop background. +def set_desktop_background(image_path): + gsettings_command = [ + "gsettings", + "set", + "org.gnome.desktop.background", + "picture-uri", + f"file://{image_path}", + ] + exitcode = subprocess.run(gsettings_command) + + gsettings_command_dark = [ + "gsettings", + "set", + "org.gnome.desktop.background", + "picture-uri-dark", + f"file://{image_path}", + ] + exitcode_dark = subprocess.run(gsettings_command_dark) + + returncode = exitcode.returncode or exitcode_dark.returncode + + if returncode == 0: + print("Desktop background set successfully.") + else: + print("Error setting desktop background.") + print("Please set the desktop background manually.") + + + +# Main program +def main(): + image_url = get_bing_image_of_the_day_url() + image_name = re.search(r"OHR\.(.*?)_", image_url).group(1) + ".jpg" + image_path = os.path.join(os.path.expanduser("~"), "Pictures", image_name) + + download_image(image_url, image_path) + set_desktop_background(image_path) + + +if __name__ == "__main__": + main()