Skip to content

Instantly share code, notes, and snippets.

@al1b
Created July 14, 2016 18:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save al1b/984f55e23430518987c49f049134d07b to your computer and use it in GitHub Desktop.
Save al1b/984f55e23430518987c49f049134d07b to your computer and use it in GitHub Desktop.
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
Copy link

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment