Python 实现获取当天的Bing图片设为壁纸并设置Ubuntu定时任务每天更新桌面

2020-03-26
上代码

#!/usr/bin/python

import requests
import time
import os

img_url = "https://area.sinaapp.com/bingImg/"

date = time.localtime()
year = date.tm_year
month = date.tm_mon
day = date.tm_mday
filename = "bing_%s_%s_%s.jpg" % (year, month, day)

print filename

with open("/home/changhengyu/code_bak/BING/pic/%s"%filename, "wb") as f:
    f.write(requests.get(img_url).content)
os.system("gsettings set org.gnome.desktop.background picture-uri 'file:///home/changhengyu/code_bak/BING/pic/%s'" % filename)

后面就是 crontab 的定时任务
crontab -e

crontab 编辑界面

最后面追加定时任务,然后Ctrl+O保存 ,回车,Ctrl+X 退出
显示

chy:~/code_bak/BING$ crontab -e 
crontab: installing new crontab

说明已经保存成功,等待事件验证

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容