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


发新话题
打印

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

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

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

posted by wap, platform: iPhone

楼上怎么用的呀?

TOP

posted by wap, platform: iPhone

我等下试试。

能否直接把那个py的文件上传一下啊?谢谢。

TOP

喷了 我还是不行。。。


RunningdeMacBook-Air:~ admin$ python bing.pty
python: can't open file 'bing.pty': [Errno 2] No such file or directory
RunningdeMacBook-Air:~ admin$


是我命令行不对嘛?

TOP

RunningdeMacBook-Air:~ admin$ python bing.py
python: can't open file 'bing.py': [Errno 2] No such file or directory
RunningdeMacBook-Air:~ admin$

刚刚多打了个 T,现在我正确输入了 还是不行啊。。。

TOP

我就放在图片的目录下啊。。。应该放在哪里?

TOP

#!/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

成功了 感谢ls,lz 还有大家

TOP

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