I created a simple script that gets the hottest post on /r/wallpapers, downloads it to a directory, and is supposed to set it as my Windows 10 wallpaper.
However, every time I run the script my wallpaper turns red. If I were to right click on my downloaded image and set it as my wallpaper, it works fine.
import praw
import urllib.request
import os
import ctypes
def main():
change_wallpaper(get_image())
def change_wallpaper(url):
SPI_SETDESKWALLPAPER = 20
directory = os.path.dirname(os.path.realpath(__file__)) + "\\bin\\" + 'image.jpg'
urllib.request.urlretrieve(url,directory)
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, directory, 0)
def get_image():
reddit = praw.Reddit(client_id='id', client_secret='secret', user_agent='app')
get_hottest = reddit.subreddit('wallpapers').hot(limit=1)
for post in get_hottest:
url = post.url
title = post.title
author = post.author
return url
main()