前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >重磅发布:一款基于GK-2A卫星云图的实时更新的桌面壁纸,欢迎试用

重磅发布:一款基于GK-2A卫星云图的实时更新的桌面壁纸,欢迎试用

作者头像
气象学家
发布2020-11-09 10:50:49
1.7K0
发布2020-11-09 10:50:49
举报
文章被收录于专栏:气象学家气象学家

最近,公众号开发了一款电脑桌面壁纸,基于韩国的静止卫星Geo-KOMPSAT-2A,实时更新。

在后台回复关键词 “GK-2A”,即可获得 GK-2A云图壁纸-第一版


GK-2A官方主页:

http://nmsc.kma.go.kr/enhome/html/base/cmm/selectPage.do?page=static.gk2amicro.gk2aMicro


Geo-KOMPSAT-

效果图(白天:RGB True,晚上:增强红外)

以下为python脚本,欢迎各路大神指点和修改。

代码语言:javascript
复制
import os,time
from datetime import datetime, timedelta
import urllib.request
import logging
import win32api,win32con,win32gui

root_path = f'{os.path.dirname(os.path.realpath(__file__))}'

def set_log(logfile= os.path.join(root_path,'log.txt')):
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    fh = logging.FileHandler(logfile, mode='a')

    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    fh.setFormatter(formatter)
    logger.addHandler(fh)
    return logger

def ceil_dt(dt, delta):
    return dt + (datetime.min - dt) % delta

class gk2awalls(object):
    """
    rule of basic images:

    full disk:
        RGB TRUE:
            https://nmsc.kma.go.kr/IMG/GK2A/AMI/PRIMARY/L1B/COMPLETE/FD/202010/30/06/gk2a_ami_le1b_rgb-true_fd010ge_202010300610.srv.png
        enhanced IR 10.5um:
            https://nmsc.kma.go.kr/IMG/GK2A/AMI/PRIMARY/L1B/COMPLETE/FD/202010/30/06/gk2a_ami_le1b_enhc-color-ir105_fd020ge_202010300640.srv.png

    East Asia:
        RGB TRUE:
        RGB NATURAL
        RGB DAYNIGHT:
            https://nmsc.kma.go.kr/IMG/GK2A/AMI/PRIMARY/L1B/COMPLETE/EA/202011/02/07/gk2a_ami_le1b_rgb-daynight_ea020lc_202011020740.srv.png
    """
    def __init__(self, time_utc, gk2a_type):
        self.time_utc = time_utc
        self.type     = gk2a_type # 'enhc-color-ir105_fd020ge'
        self.status   = False
        self.remote_path = 'https://nmsc.kma.go.kr/IMG/GK2A/AMI/PRIMARY/L1B/COMPLETE/EA/' + \
            self.time_utc.strftime('%Y%m') + '/' + self.time_utc.strftime('%d') +'/'+ self.time_utc.strftime('%H') + '/' + \
            'gk2a_ami_le1b_{}_{}.srv.png'.format(self.type, self.time_utc.strftime('%Y%m%d%H%M'))
        self.local_path  = os.path.join(root_path,'images',
            self.time_utc.strftime('%Y%m'), self.time_utc.strftime('%d'), self.time_utc.strftime('%H'),
            'gk2a_ami_le1b_{}_{}.srv.png'.format(self.type, self.time_utc.strftime('%Y%m%d%H%M')))

        self._check_is_get()
        if os.path.exists(self.local_path) and os.path.getsize(self.local_path) > 10000:
            self.status = True
            self._set_wallpaper()

    def _check_is_get(self):
        with urllib.request.urlopen(self.remote_path) as res:
            info = res.info()
            if info.get('Content-Type') == 'image/png': 
                logger.info(f'remote found {self.remote_path}')
                if os.path.exists(self.local_path):
                    if float(info.get("Content-length")) == os.path.getsize(self.local_path):
                        logger.info(f'Already downloaded of {self.local_path}')
                    else:
                        self._get_png(res.read(), self.local_path)
                else:
                    self._get_png(res.read(), self.local_path)
            else:
                logger.warning(f'not found {self.remote_path}') 

    @staticmethod
    def _get_png(data, local_path):
        if not os.path.exists(os.path.dirname(local_path)): os.makedirs(os.path.dirname(local_path))
        with open(local_path, 'wb') as f:
            f.write(data)
            logger.info(f'Download Success of {local_path}')
        return

    def _set_wallpaper(self, loc=6):
        key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,"Control Panel\\Desktop",0,win32con.KEY_SET_VALUE)
        win32api.RegSetValueEx(key, "WallpaperStyle", 6, win32con.REG_SZ, "6") 
        win32api.RegSetValueEx(key, "TileWallpaper", 0, win32con.REG_SZ, "0")
        win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, self.local_path, win32con.SPIF_SENDWININICHANGE)
        logger.info(f'Set {self.local_path}')
        return

if __name__ == "__main__":
    '''
    This code set GK2A satellite basic image as wallpaper
    '''
    logger = set_log()

    # enhance IR 10.5
    gk2a_type = 'rgb-daynight_ea020lc'
    while True:
        time_now = datetime.utcnow()
        time_now = ceil_dt(time_now, timedelta(minutes=10))
        # check 1hour ago
        for imn in range(0,60,10):
            time_r = time_now - timedelta(minutes=imn)
            if float(time_r.strftime('%H')) >= 0 and  float(time_r.strftime('%H')) <= 7:
                gk2a_type = 'rgb-true_ea010lc'
            else:
                gk2a_type = 'enhc-color-ir105_ea020lc'
            gk2a_d = gk2awalls(time_r, gk2a_type)
            if gk2a_d.status: break

        time.sleep(60*5) # sleep 5 minutes
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-11-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 气象学家 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档