1命令
1.1 设置壁纸命令
gsettings set org.gnome.desktop.background picture-uri "file:/home/leon/pic/111.jpg"
1.2 设置壁纸图片居中
gsettings set org.gnome.desktop.background picture-options 'centered'
2 python调用
gsettings set org.gnome.desktop.background picture-uri "file:/home/amazing/python/ChangeWallPaper/Bing/20191009.jpg"
3 更换为bing的壁纸
# -*- coding: utf-8 -*-
import urllib
import requests
import time
import os
import sys
import re
from PIL import Image
headers = {
'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6',
}
class StealBing:
def __init__(self):
self.zhuzhan = "https://cn.bing.com/"
self.content = requests.get(self.zhuzhan,headers = headers).content
self.bgImageUrl = ''
self.localFileName = ''
def parserImageURL(self):
#g_img={url: "/az/hprichbg/rb/PortAntonio_ZH-CN10325538004_1920x1080.jpg"}
reg = re.compile('g_img={url:(.*?jpg)')
data = self.content.decode('utf-8')
self.bgImageUrl = reg.findall(data)
cut = self.bgImageUrl[0][2:]
self.bgImageUrl = self.zhuzhan + cut
def createLocalFileName(self):
path = os.getcwd() + '/Bing/'
if not os.path.exists(path):
os.mkdir(path)
randomStr = time.strftime("%Y%m%d", time.localtime())
self.localFileName = path + randomStr + '.jpg'
def downloadImage(self):
if self.bgImageUrl == '':
self.parserImageURL()
if self.localFileName == '':
self.createLocalFileName()
urllib.request.urlretrieve(self.bgImageUrl, self.localFileName)
def update(self):
cmd = "gsettings set org.gnome.desktop.background picture-uri "file:"+self.localFileName+"""
os.system(cmd)
if __name__ == '__main__':
stealBing = StealBing()
stealBing.downloadImage()
stealBing.update()