Skip to content

Instantly share code, notes, and snippets.

@al1b al1b/bing-wall.py
Created Jul 14, 2016

Embed
What would you like to do?
A Python script to download today picture of Bing.com and set it as Windows Desktop wallpaper.
import re, os, tempfile
import urllib.request
from urllib.parse import urlparse
def getBing():
url = 'http://bing.com/'
response = urllib.request.urlopen(url)
data = response.read()
return data.decode('utf-8')
def downloadFile(url, file_name):
urllib.request.urlretrieve(url, file_name)
if __name__ == "__main__":
url = re.search('g_img=\{url: \"(.*?)\"', getBing()).group(1).replace('\/', '/')
url = 'http://bing.com' + url
fileName = tempfile.gettempdir() + '\\' + url.rsplit('/', 1)[-1]
downloadFile(url, fileName)
os.system('reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d {} /f'.format(fileName));
os.system('reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v WallpaperStyle /t REG_SZ /d 10 /f');
os.system('RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True')
print(fileName)
@hadi-jabbari

This comment has been minimized.

Copy link

commented Jul 15, 2016

nice

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.