调用Bing桌面更换为本地桌面的python方法,bingpython,这是一篇关于调用Bing
调用Bing桌面更换为本地桌面的python方法,bingpython,这是一篇关于调用Bing
这是一篇关于调用Bing桌面更换为本地桌面的python方法,因代码创建时间比较久,如要使用请做修改。
# -*- coding: cp936 -*-'''Created on 2009-8-17'''import osimport sysimport randomimport urllibimport win32guiimport win32conimport Imageclass StealBing: def __init__(self): self.content = urllib.urlopen('http://cn.bing.com/').read() self.bgImageUrl = '' self.localFileName = '' self.localBMPFileName = '' def parserImageURL(self): tempStr = self.content[self.content.index('g_img={url:')+12:len(self.content)] tempStr = tempStr[0:tempStr.index(',id:')-1] tempStr = tempStr.replace('\\', '') self.bgImageUrl = 'http://cn.bing.com'+tempStr #仅用于生成本地文件名 #www.iplaypy.com def createLocalFileName(self): randomStr = ''.join(random.sample(['a','b','c','d','e','f','g','h','i','j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], 6) ).replace(" ","") self.localFileName = 'c:/temp/' + randomStr + '.jpg' self.localBMPFileName = 'c:/temp/' + randomStr + '.bmp' def downloadImage(self): if self.bgImageUrl == '': self.parserImageURL() if self.localFileName == '': self.createLocalFileName() data = urllib.urlretrieve(self.bgImageUrl, self.localFileName) def updataBGImage(self): img = Image.open(self.localFileName) img.save(self.localBMPFileName) os.remove(self.localFileName) win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, self.localBMPFileName , 0) if __name__ == '__main__': stealBing = StealBing() stealBing.downloadImage() stealBing.updataBGImage()
编橙之家文章,
相关内容
- Python编写的俄罗斯方块游戏案例源码详解,PYQT4,pyth
- python采集文章中图片的方法源码,,这是收集的一篇关于
- Python tar、zip压缩文件操作方法,pythontar,python语言源码
- Python调用摄像头摄像并保存图片的方法源码,,用pytho
- Python 类快速排序方法找到第定n小数的方法,python小数
- Python实现SYSLOG服务器与MYSQL数据库写入源码,pythonsysl
- python方法判断IP的合法性源码分享,python合法性,用pyt
- Python代码音乐mp3下载器源码分享,python下载器,用pytho
- python方法实现磁盘剩余空间查询操作,python磁盘,想知道
- python转换工具之汉语拼音与国际音标的实现,python转换
评论关闭