Python 实现获取当天的Bing图片设为壁纸并设置Ubunt
2020-03-26 本文已影响0人
欧德朗
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
最后面追加定时任务,然后
Ctrl+O
保存 ,回车
,Ctrl+X
退出显示
chy:~/code_bak/BING$ crontab -e
crontab: installing new crontab
说明已经保存成功,等待事件验证