» 您尚未登录:请 登录 | 注册 | 标签 | 帮助 | 小黑屋 |


发新话题
打印

[其他] 中年入门程序员作品,Mac下自动下载Bing每日墙纸的Python script,16楼

posted by wap, platform: Chrome

#!/usr/bin/env python
import os
import pprint
import sys
import subprocess
import urllib2
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';
url = 'http://www.bing.com'
size = '1920x1080'
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(url):
        destination = "%s%s.jpg" % (dst_dir, strftime( "%y-%m-%d")
        if os.path.exists(destination):
                sys.exit(0)

        req = urllib2.Request(url)
        content = urllib2.urlopen(req).read()
        link = content[content.index('g_img={url:') + len('g_img={url:') + 1 : len(content)]
        link = link[0 : link.index(',id:') - 1]
        links =  link.split('_')
        link = links[0] + '_' + links[1] + '_' + size + '.jpg'
        print link
        URLopener().retrieve(link, destination)
        set_desktop_background(destination)

def main():
        parseFeed(url)

if __name__ == "__main__":
        main();


本帖最近评分记录
  • eva3d 激骚 +5 感谢分享 2013-9-26 08:56

TOP

发新话题
     
官方公众号及微博