Created
July 14, 2016 18:19
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice