找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 15422|回复: 0

[原创代码] 设置bing.com背景为壁纸,Python版

[复制链接]
发表于 2018-2-16 01:33:38 | 显示全部楼层 |阅读模式
没啥好说的,论坛很多以bing做壁纸的,再补上Python版本的
  1. #**************
  2. #coding=utf-8  
  3. #by ivor
  4. #设置bing.com背景为壁纸



  5. import re
  6. import requests
  7. import pythoncom  
  8. from win32com.shell import shell, shellcon  


  9. class MyPaper:
  10.    
  11.     def __init__(self):
  12.         self.image = r"C:\paper.jpg"
  13.         self.url = r'https://cn.bing.com/'
  14.         
  15.     def getDeskComObject(self):  
  16.         self.g_desk = None
  17.         if not self.g_desk:  
  18.             self.g_desk = pythoncom.CoCreateInstance(shell.CLSID_ActiveDesktop, \
  19.             None, pythoncom.CLSCTX_INPROC_SERVER, \
  20.             shell.IID_IActiveDesktop)
  21.         return self.g_desk  

  22.     def setWallPaper(self):
  23.         self.desktop = self.getDeskComObject()
  24.         if self.desktop:
  25.             self.desktop.SetWallpaper(self.image, 0)
  26.             self.desktop.ApplyChanges(shellcon.AD_APPLY_ALL)
  27.             
  28.     def addUrlLink(self, lnk):  
  29.         self.desktop = self.getDeskComObject()
  30.         self.desktop.AddUrl(0, lnk, 0, 0)
  31.         
  32.     def imgDownload(self):
  33.         r = requests.get(self.url).content
  34.         pattern = re.compile(r'url: "(.*jpg)?')
  35.         imgUrl = re.findall(pattern,r.decode(encoding="utf-8"))

  36.         imgData = requests.get(self.url + imgUrl[0]).content
  37.         with open(self.image ,"wb") as file:
  38.             file.write(imgData)


  39. setPaper = MyPaper()
  40. setPaper.imgDownload()
  41. setPaper.setWallPaper()
复制代码

评分

参与人数 1PB +6 收起 理由
523066680 + 6 6

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-16 22:21 , Processed in 0.018797 second(s), 9 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表