#-*-coding:utf-8-*-
from bs4 import BeautifulSoup
import requests
import time
import os
import PyWallpaper
import win32api
import win32gui
import win32con
from PIL import Image
def set_wallpaper_from_bmp(bmp_path):
reg_key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, win32con.KEY_SET_VALUE)
win32api.RegSetValueEx(reg_key, "WallpaperStyle", 0, win32con.REG_SZ, "2")
win32api.RegSetValueEx(reg_key, "TileWallpaper", 0, win32con.REG_SZ, "0")
win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, bmp_path, win32con.SPIF_SENDWININICHANGE)
def set_wallpaper(file_path):
bmpImage = Image.open(file_path)
img_dir = "D:\wallpaper\\"
print("IMage:dir")
print(img_dir)
new_bmp_path = os.path.join(img_dir,'wallpaper.bmp')
bmpImage.save(new_bmp_path,"BMP")
set_wallpaper_from_bmp(new_bmp_path)
content = requests.get("https://cn.bing.com/?mkt=zh-CN").text
soup = BeautifulSoup(content,'html.parser')
image_url = "https://cn.bing.com/" + soup.find(id="bgLink")["href"]
print(image_url)
str_time = time.strftime("%Y-%m-%d")
month = time.strftime("%m")
img = requests.get(image_url)
image_path = r"D:\bing\%s"%(month)
image_full_path = r"D:\bing\%s\%s.jpg"%(month,str_time)
if img.status_code == 200:
folder = os.path.exists(image_path)
if not folder:
os.mkdir(image_path)
with open(r"D:\bing\%s\%s.jpg"%(month,str_time),'wb') as file:
file.write(img.content)
set_wallpaper(image_full_path)
python下载每日必应壁纸
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 喜欢Bing壁纸,考虑把它设置到自己一个插件的背景,但想从一个固定的地址获取图片。就打算用写一个脚本定时获取Bin...