可是当我,rc.local加入
代码: 全选
su jj -c 'echo /home/jj/bin/autorun/BingPicture.py | at now + 10 minutes'
代码: 全选
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import re, urllib, os
from Logger import Logger
class BingPicture:
'''
download bing.com background picture
and set the picture as gnome wallpaper
'''
version = 1.0
def __init__(self):
self.bingUrl = "http://www.bing.com"
self.downloadFolder = "/home/jj/Pictures/bing/"
self.commad = "gconftool-2 -t str --set /desktop/gnome/background/picture_filename "
self.log = Logger("bing")
def go(self):
filename = self.downloadPicture()
# if the file is not None, let's set it as wallpaper
if filename != None:
os.system(self.commad + self.downloadFolder + filename)
def getHtml(self):
# return www.bing.com's page html code
f = urllib.urlopen(self.bingUrl)
bingString = ''
for i in f:
bingString += i
return bingString
def downloadPicture(self):
# download the picture we want
# @return the filename of the picture
# first we retrive the url of the picture
bingString = self.getHtml()
tmp = re.search("g_img={url:.*jpg", bingString).group()
tmp = tmp.replace("\\", '')
picUrl = tmp.rsplit("'")[1]
picUrl = "http://www.bing.com" + picUrl
# filename of the picture
picFilename = tmp.rsplit("/", 1)[1]
# before we download the picture, let's check it
# whether we have already downloaded it. we should avoid repeated work
if os.path.isfile(self.downloadFolder + picFilename):
self.log.log("we have already downloaded it. we will not do it again")
else:
# OK, let's download it
urllib.urlretrieve(picUrl, self.downloadFolder + picFilename)
self.log.log("OK, a picture is downloaded.")
return picFilename
if __name__ == "__main__":
bp = BingPicture()
bp.go()