每日自动切换壁纸

python代码如下

import  requests
import  re
import  os

headers={
    'user-agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36'
}

def getphotourl(host): #解析主页获取大图路径
    text=requests.get(host,headers=headers).text
    zz =re.compile(r'/az/hprichbg/rb/[\s\S]*?.jpg')
    return re.findall(zz,text)[0]

def dowloadphoto(host,url):  #下载图片并返回图片路径
    path='F:/user/'+url.split('/')[-1]
    print('path={str}'.format(str=path))
    content=requests.get(host+url,headers=headers).content
    with open(path,'wb') as f:
        f.write(content)
        f.close()
        return path

def main():
    host = "https://cn.bing.com/"
    fileurl=getphotourl(host)
    print(fileurl)
    path=dowloadphoto(host,fileurl)  #接受返回的文件路径
    print(path)
    str=r"REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System  /v Wallpaper   /t REG_SZ  /d "
    str2=r" /reg:64  /f"
    command=str+path+str2
    print(command)
    os.system(command)   #设置壁纸
    # os.system("taskkill /f /im explorer")
    # os.system('start c:/windows/explorer.exe')  #刷新注册表

if __name__ == '__main__':
    main()

使用pyinstaller 编译后

pyinstaller filename.py

添加到系统中的任务计划程序,即可每日更换壁纸



  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值