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

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

你可能感兴趣的:(Python 实现获取当天的Bing图片设为壁纸并设置Ubuntu定时任务每天更新桌面)