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


发新话题
打印

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

好吧,全部写完了...... 这年头还是得靠自己啊...  有需要的拿去,明天继续研究如何让这个py自动定时运行

Mac下,在图片目录里面建立一个 DeskFeed 的目录,把代码保存为“随便什么名字.py” 然后终端里面运行 python 随便什么名字.py
理论上马上壁纸就会更换了
复制内容到剪贴板
代码:
#!/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();


TOP

posted by wap, platform: iPad

支持下中年人



TOP

支持下,一直想着咋存每天喜欢的bing壁纸。


TOP

adsl-172-10-1-115:~ admin$ python bing.py
python: can't open file 'bing.py': [Errno 2] No such file or directory
adsl-172-10-1-115:~ admin$


我怎么不行呀。。。

TOP

posted by wap, platform: Firefox

图片目录下面建立 DeskFeed目录了么

TOP

不错,今日桌面已取到~来支持下

TOP

posted by wap, platform: Android

弄个apk吧,用着的bing daily wallpaper应用好像不是full hd墙纸。

TOP

posted by wap, platform: iPhone

赞一个,谢楼主

TOP

posted by wap, platform: GOOGLE (Nexus 4)

WIN下直接搜Bingwallpaper有现成的软件可以每天换……

TOP

感谢分享,为了bing的壁纸我专门装了bing搜索

TOP

不错不错
虽然mac上基本很少看到桌面- -

TOP

昨晚把开机运行的也搞定了..   
在应用程序里打开Automator,建立应用程序


然后在左边选择实用工具,再选择运行Shell工具,其他设置如图
我这里的情况是假设16楼的script保存为bing.py,存放在 ~/Pictures/bing.py,注意路径必须是绝对路径,不能用~/,而必须用/Users/你的用户名/


Automator保存为一个应用文件,随便放哪里都可以,我是放应用程序里面了
在系统偏好设置(齿轮)里打开用户与群组,选择对应你的用户名,点击右边上方的登录项,把之前用Automator建立的应用程序添加到启动项目,下次开机就自动执行了,壁纸每日开机一换,今天开机直接就换成海云台夜景了
附件: 您所在的用户组无法下载或查看附件

TOP

bing.py 放在哪里有要求吗?我怎么还是没法用?

TOP

我已经有DeskFeed了啊。。。
附件: 您所在的用户组无法下载或查看附件

TOP

adsl-172-10-1-115:~ admin$ python /users/admin/pictures/bing.py
  File "/users/admin/pictures/bing.py", line 1
SyntaxError: Non-ASCII character '\xff' in file /users/admin/pictures/bing.py on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
adsl-172-10-1-115:~ admin$


我打路径了也不行。。。

TOP

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