zoukankan      html  css  js  c++  java
  • Python脚本一键设置Bing搜索背景设为windows桌面壁纸脚本

    一键设置Bing搜索背景设为windows桌面壁纸脚本 配置完脚本再设置windows定时任务即可每天更换桌面背景
    import requests
    import json
    import sys
    from datetime import datetime
    import os
    import win32api,win32con,win32gui
    
    url = 'https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&nc=1603413047356&pid=hp&FORM=Z9FD1'
    
    res = requests.get(url)
    
    res_json = json.loads(res.text)
    # print(res_json['images'][0]['url'])
    image_name = res_json['images'][0]['copyright'].split('(')[0]
    print(image_name)
    #获取图片地址 根据地址拼接url
    bing_url = 'https://cn.bing.com{}'.format(res_json['images'][0]['url'])
    
    # print(bing_url)
    
    image_res = requests.get(bing_url)
    
    basePath = sys.path[0]
    
    
    # print(os.path.dirname(basePath))
    #当前路径是否为文件 是文件则取父目录
    if (os.path.isfile(basePath)):
        basePath = os.path.dirname(basePath)
    baseFoler = basePath + '\Download\'
    #创建Download文件夹
    if(not os.path.exists(baseFoler)):
        os.makedirs(baseFoler)
    jpgfile = basePath + '\' +image_name
    jpgfile = baseFoler + image_name + str(datetime.now().strftime('%Y-%m-%d'))+'.jpg'
    print(jpgfile)
    #保存图片
    with open(jpgfile,'wb') as file:
        file.write(image_res.content)
    
    
    
    print(u'正在设置图片:%s为桌面壁纸...' % image_name)
    key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,
                                "Control Panel\Desktop",0,win32con.KEY_SET_VALUE
                                )
    win32api.RegSetValueEx(key,"WallpaperStyle",0,win32con.REG_SZ,"2")
    #2拉伸适应桌面,0桌面居中
    win32api.RegSetValueEx(key,"TileWallpaper",0,win32con.REG_SZ,"0")
    win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER,jpgfile,1+2)
    
    print(u'成功应用图片:%s为桌面壁纸'  % image_name)
  • 相关阅读:
    进制转换
    01背包基础
    6-14 Inspector s Dilemma uva12118(欧拉道路)
    9-4 Unidirectional TSP uva116 (DP)
    8-4 奖品的价值 uva11491(贪心)
    9-1 A Spy in the Metro uva1025 城市里的间谍 (DP)
    8-3 Bits Equalizer uva12545
    8-2 Party Games uva1610 (贪心)
    自动发邮件功能
    窗口截图.py
  • 原文地址:https://www.cnblogs.com/zzay/p/13862528.html
Copyright © 2011-2022 走看看