魔王撒旦
小白屋
#!/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 #get bing wallpaper # Defines source and destination of image rss_feed = 'http://cn.bing.com/'; 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) startString ="g_img={url:'" 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() print rss_src spPos = rss_src.find(startString) if spPos == -1: return startPos = spPos + len(startString) endPos = rss_src.find("'",startPos) if endPos == -1: return link = rss_src[startPos:endPos].replace('1366x768','1920x1080') URLopener().retrieve(link, destination) set_desktop_background(destination) def main(): parseFeed(rss_feed) if __name__ == "__main__": main()
查看详细资料
TOP