直接给出源码
设置壁纸
1feh --bg-scale /tmp/earth.png
设置桌面大小,及图片放大倍数
1SCALE = 4
2WIDTH = 1368
3HEIGHT = 768
1from PIL import Image
2from io import BytesIO
3from urllib.request import Request, urlopen
4from datetime import datetime
5import json
6
7SCALE = 4
8WIDTH = 1368
9HEIGHT = 768
10
11
12def get_info():
13 url = "http://himawari8-dl.nict.go.jp/himawari8/img/D531106/latest.json"
14 request = Request(url)
15 response = urlopen(request, timeout=10)
16 return json.loads(response.read())
17
18
19def download():
20 png = Image.new('RGB', (550 * SCALE, 550 * SCALE))
21 desktop = Image.new('RGB', (WIDTH, HEIGHT))
22 url_format = 'http://himawari8-dl.nict.go.jp/himawari8/img/D531106/{}d/{}/{}_{}_{}.png'
23 info = get_info()
24 date = datetime.strptime(info['date'], '%Y-%m-%d %H:%M:%S')
25 for x in range(SCALE):
26 for y in range(SCALE):
27 url = url_format.format(SCALE, 550,
28 date.strftime("%Y/%m/%d/%H%M%S"), x, y)
29 print(url)
30 request = Request(url)
31 response = urlopen(request, timeout=10)
32 img = Image.open(BytesIO(response.read()))
33 png.paste(img, (550 * x, 550 * y, 550 * (x + 1), 550 * (y + 1)))
34 png.thumbnail((HEIGHT, HEIGHT), Image.ANTIALIAS)
35 desktop.paste(png, ((WIDTH - HEIGHT) // 2, 0))
36 desktop.save('/tmp/earth.png', "PNG")
37
38if __name__ == '__main__':
39 download()
知识共享署名-非商业性使用-相同方式共享4.0国际许可协议