Python crawls FY-4 as desktop background

First of all, the last effect is that there is only a recycle bin on the desktop. I found a picture of FY-4 and clicked the picture below to make an ico icon. Then I gave the name of the recycle bin. The satellite is equipped with pictures taken by myself, which is a bit interesting.
Insert picture description here
FY-4 hourly image sources are as follows, just pull it every hour → http://img.nsmc.org.cn/CLOUDIMAGE/FY4A/MTCC/FY4A_DISK.JPG

Copy from east to west, change it yourself, the code is as follows

import requests
import os
import win32api, win32con, win32gui
from PIL import Image
import numpy as np
import time

# 爬取风云四数据
def _get_fy_img():
    url = 'http://img.nsmc.org.cn/CLOUDIMAGE/FY4A/MTCC/FY4A_DISK.JPG'
    res = requests.get(url)
    # 保存壁纸
    with open('background.jpg', 'wb') as f:
        f.write(res.content)

# 设置为壁纸
def set_background(imgpath):
    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, imgpath, win32con.SPIF_SENDWININICHANGE)

# 图像获取和处理
def get_and_deal_img():
    bk_path = 'background.jpg'
    # 读图像(图像形状:2198,2198,3)
    bk_img = np.array(Image.open(bk_path))
    # 删除图像
    os.remove(bk_path)
    ## 处理水印
    # 左上水印
    bk_img[0:174, 0:447, :] = 0
    # 右下水印
    bk_img[1970:2198, 1970:2198, :] = 0
    # 扩展壁纸到电脑显示器大小
    bk_img = Image.fromarray(np.uint8(bk_img))
    # 缩放到720*720,铺满电脑或者露个半截有啥好看的
    bk_img = bk_img.resize((720, 720), Image.ANTIALIAS)
    # 电脑屏幕大小那么大的0图片
    bks_img = np.zeros((1080, 1920, 3))
    # 中间换了
    bks_img[180:900, 600:1320, :] = bk_img
    # 重新保存图像
    Image.fromarray(np.uint8(bks_img)).save(bk_path)
    # 加载桌面
    path = os.getcwd()
    set_background(os.path.join(path, bk_path))

if __name__ == '__main__':
    get_and_deal_img()

When you're done, get a Windows scheduled task, just send it out every hour.

  • win+R, enter taskschd.msc , create task
    Insert picture description here

  • Set up the name and introduction
    Insert picture description here

  • Set trigger, trigger once per hour, loop
    Insert picture description here

  • Set the running script, just write this in the script. The first E: means that the py file is on the e drive, the second cd to the path of the py file, and then run the .pyw file with pythonw (my file name is FY-4.pyw).
    Note: Change .py to .pyw, use pythonw to run without a black frame interface

@echo off

E:

cd E:\MyData\script

pythonw FY-4.pyw
  1. Program and script are the full path of bat script
  2. Start with the path of the bat script, not including XX.bat
    Insert picture description here
    ok

Guess you like

Origin blog.csdn.net/qq_39798423/article/details/109649007