毛熊爸
魔神至尊
苹果神教
#!/usr/bin/env python import os import md5 import pprint import sys import subprocess from time import strftime from urllib import URLopener from urllib2 import urlopen from xml.dom.minidom import parseString # Defines source and destination of image rss_feed = 'http://feeds.feedburner.com/bingimages'; dst_dir = os.path.expanduser('~/Pictures/DeskFeed/') # Originally found on: http://hints.macworld.com/article.php?story=20110721062846337 # Applescript modified for dual monitors by: ViVIDboarder SCRIPT = """/usr/bin/osascript<<end tell application "System Events" set picture of every desktop to POSIX file "%s" end tell END""" def set_desktop_background(destination): subprocess.Popen(SCRIPT%destination, shell=True) def parseFeed(rss): destination = "%s%s.jpg" % (dst_dir, strftime( "%y-%m-%d") if os.path.exists(destination): sys.exit(0) try: rss_contents = urlopen( rss ) except: print "Failed to read rss feed %s" % rss return rss_src = rss_contents.read() rss_contents.close() dom = parseString( rss_src ) firstitem = dom.getElementsByTagName('item')[0] link = firstitem.getElementsByTagName( 'enclosure' )[0].getAttribute('url') URLopener().retrieve(link, destination) set_desktop_background(destination) def main(): parseFeed(rss_feed) if __name__ == "__main__": main()
background-image:url(http://s.cn.bing.net/az/hprichbg/rb/AustriaAutumn_ZH-CN11875113209_1366x768.jpg)
http://s.cn.bing.net/az/hprichbg/rb/AustriaAutumn_ZH-CN11875113209_1366x768.jpg
http://s.cn.bing.net/az/hprichbg/rb/AustriaAutumn_ZH-CN11875113209_1920x1080.jpg
查看详细资料
TOP
原帖由 @蚁力神 于 2013-9-25 14:04 发表 猫熊爹你不觉得你太高端了么
#---------------------------------import--------------------------------------- import urllib2; import re; #------------------------------------------------------------------------------ def main(): userMainUrl = "http://cn.bing.com"; req = urllib2.Request(userMainUrl); resp = urllib2.urlopen(req); respHtml = resp.read(); WallPaper = re.search("g_img={url:'(?P<wpurl>.+?)'", respHtml); print "WallPaper=",WallPaper; if(WallPaper): wpurl = WallPaper.group("wpurl"); print "wpurl=",wpurl; newurl = wpurl.replace('1366x768','1920x1080'); print "newurl=",newurl; ############################################################################### if __name__=="__main__": main();
python test.py WallPaper= <_sre.SRE_Match object at 0x106502468> wpurl= http://s.cn.bing.net/az/hprichbg/rb/AustriaAutumn_ZH-CN11875113209_1366x768.jpg newurl= http://s.cn.bing.net/az/hprichbg/rb/AustriaAutumn_ZH-CN11875113209_1920x1080.jpg
#!/usr/bin/env python import os import md5 import pprint import sys import subprocess import urllib2 import re from time import strftime from urllib import URLopener from urllib2 import urlopen from xml.dom.minidom import parseString dst_dir = os.path.expanduser('~/Pictures/DeskFeed/') SCRIPT = """/usr/bin/osascript<<END tell application "System Events" set picture of every desktop to POSIX file "%s" end tell END""" def set_desktop_background(destination): subprocess.Popen(SCRIPT%destination, shell=True) def main(): userMainUrl = "http://cn.bing.com"; req = urllib2.Request(userMainUrl); resp = urllib2.urlopen(req); respHtml = resp.read(); WallPaper = re.search("g_img={url:'(?P<wpurl>.+?)'", respHtml); # print "WallPaper=",WallPaper; if(WallPaper): wpurl = WallPaper.group("wpurl"); # print "wpurl=",wpurl; newurl = wpurl.replace('1366x768','1920x1080'); # print "newurl=",newurl; destination = "%s%s.jpg" % (dst_dir, strftime( "%y-%m-%d")); URLopener().retrieve(newurl, destination) set_desktop_background(destination) if __name__=="__main__": main();