By iftttauthorways4eu
on Sat Feb 11 2023
Here’s a Python script that downloads the NASA Picture of the Day and sets it as the background image in Windows:
Read more: How to Automatically Set NASA’s Picture of the Day as Your Windows Background
import requests
import ctypes
import json
# URL for NASA's Picture of the Day API
# for test purpose use DEMO_KEY as api_key
# url = "https://api.nasa.gov/planetary/apod?api_key=YOUR_API_KEY"
url = "https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY"
# windows full file path
# adjust this to your environment
WIN_FILEPATH = "D:\\scripts\\win\\setBackgroundPicNASA\\bg_wallpaper.jpg"
# Request the data from the API
response = requests.get(url)
data = json.loads(response.text)
# Get the URL of the image
img_url = data["hdurl"]
# Download the image
response = requests.get(img_url)
open(WIN_FILEPATH, "wb").write(response.content)
# Set the image as the background
SPI_SETDESKWALLPAPER = 20
ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, WIN_FILEPATH, 0)
Note that you will need to replace “YOUR_API_KEY” in the URL with your own NASA API key, which you can obtain from the NASA API website (https://api.nasa.gov/).
The script first makes a request to the NASA API to retrieve the data for the Picture of the Day. It then parses the data and extracts the URL of the image. The image is then downloaded and saved as image-file. Finally, the script sets the image as the Windows desktop background using the ctypes library.
You can download the sourcecode and find more details on my github-repository:
https://github.com/smartDevel/set_nasa_pic_as_background
The post How to Automatically Set NASA’s Picture of the Day as Your Windows Background appeared first on Strictly Confidential.