毛熊爸
魔神至尊
苹果神教
#!/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 发表 猫熊爹你不觉得你太高端了么
原帖由 ffcactus 于 2013-9-25 14:33 发表 关键是没几个人现在用 Mac 并装了python呀。
魔王撒旦
小黑屋
原帖由 @zztg 于 2013-9-25 14:40 发表 虽然明知ff是吃了药....不过我还是说下osx自带了python....而且10.9也把版本跟进到2.7.5了....10.8好像还是2.7
#---------------------------------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
侠客
时靸双鸳响
廊叶秋声
原帖由 ffcactus 于 2013-9-25 06:33 发表 关键是没几个人现在用 Mac 并装了python呀。
原帖由 ffcactus 于 2013-9-25 07:07 发表 posted by wap, platform: iPhone 我又没有mac,我怎么知道带不带,你们全家吃了药还差不多,用苹果的神经病果然比较多。
小白屋
#!/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()
魔头
import httplib2 import os.path h = httplib2.Http('cache') headers = {'Content-type': 'application/x-www-form-urlencoded'} url = 'http://www.bing.com/' response, content = h.request(url, 'GET') htmlContent = content.decode('utf-8') imageUrl = htmlContent[htmlContent.find(';g_img'):] imageUrl = imageUrl[imageUrl.find("'") + 1:] imageUrl = imageUrl[:imageUrl.find("'")] imageUrl = imageUrl.replace('1366x768', '1920x1080') print(imageUrl) response, content = h.request(imageUrl, 'GET') imageFile = open(os.path.basename(imageUrl), 'wb') imageFile.write(content) imageFile.close()