Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Sets your wallpaper to NASA's picture of the day
import requests
from bs4 import BeautifulSoup
from os import path, getcwd
import ctypes
import time
def windowswallpaper(image):
ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, image, 0)
def getimage(url):
#Get the data from the website
page = requests.get(url)
soup = BeautifulSoup(page.content, "html.parser")
date = soup.findAll("p")[1].text.strip()
image = soup.find("img")
url += image["src"]
page = requests.get(url)
filename = f"image {date}.jpg"
# Create the .jpg file
with open(filename, "wb") as f:
#Set the wallpaper to the .jpg file
url = ""
#Change the extension from .pyw to .py if you want the console window
#If you want the program to be run at startup go to:
#C:\Users\current_user\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
#And drag the file .pyw/.py file in there
#If you want the program to be ran between some time periods you should use Windows Task Scheduler
#If you do not know how to check out

This comment has been minimized.

Copy link

majze commented Jan 16, 2020

Thanks, this is great!

If anyone has issues running on Windows, this may help:
pip3 install requests
pip3 install beautifulsoup4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.