linux自动每日更新桌面背景

来源:互联网 发布:淘宝什么匿名评价 编辑:程序博客网 时间:2024/04/29 07:22

每天定时(cron)抓取bing的主页图片作为linux桌面背景,以下是python脚本

import urllibimport reimg_p = re.compile(r'g_img={url:\'(.*?)\'', re.I | re.M | re.S)#download bing homepagecontent = urllib.urlopen('http://cn.bing.com/').read()#find backgroud image urlm = re.search(img_p, content)if m is not None:    img_url = m.group(1)    name = img_url.split('/')[-1]    #replace special character    name = name.replace('=', '_').replace('?', '_').replace('%', '_')    name = '/path/to/%s' % name    #save backgroud image    urllib.urlretrieve(img_url, name)    #refresh desktop backgroud    import os    os.system('gsettings set org.gnome.desktop.background picture-uri "file://%s"' % name)

crontab: 30 8 * * * env DISPLAY=:0 python refresh_gb.py 注意,如果不加env DISPLAY=:0是没法更新桌面背景的,因为cron默认是后台操作,无法修改UI

原创粉丝点击