Python 實現(xiàn)獲取當天的Bing圖片設(shè)為壁紙并設(shè)置Ubuntu定時任務(wù)每天更新桌面

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 的定時任務(wù)
crontab -e

crontab 編輯界面

最后面追加定時任務(wù),然后Ctrl+O保存 ,回車,Ctrl+X 退出
顯示

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

說明已經(jīng)保存成功,等待事件驗證

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容