之前的卫星云图壁纸,偏重科学,这个地球壁纸多了一些艺术,会随着光照出现阴影,就像月盈月缺。
代码
如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import datetime
import os
import tempfile
from urllib import request
import win32api
import win32con
import win32gui
from PIL import Image
class Wallpaper:
def __init__(self):
self.image = os.path.join(tempfile.gettempdir(), "wallpaper.png")
def crawl(self):
url_base = "https://himawari8-dl.nict.go.jp/himawari8/img/D531106/1d/550/"
t = datetime.datetime.now(datetime.UTC)
date = t - datetime.timedelta(hours=1, minutes=t.minute % 10)
ext = "00_0_0.png"
picture_url = url_base + date.strftime("%Y/%m/%d/%H%M") + ext
res = request.urlopen(picture_url)
with open(self.image, "wb") as f:
f.write(res.read())
return self
def zoom(self):
h = win32api.GetSystemMetrics(win32con.SM_CYSCREEN)
Image.open(self.image).resize((h - 100, h - 100), Image.Resampling.LANCZOS).save(self.image)
return self
def setup(self):
keyex = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, win32con.KEY_SET_VALUE)
win32api.RegSetValueEx(keyex, "WallpaperStyle", 0, win32con.REG_SZ, "0")
win32api.RegSetValueEx(keyex, "TileWallpaper", 0, win32con.REG_SZ, "0")
win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, self.image, win32con.SPIF_SENDWININICHANGE)
if __name__ == "__main__":
wallpaper = Wallpaper()
wallpaper.crawl().zoom().setup()
效果
如图所示:

