调用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()

编橙之家文章,

评论关闭