From db9153f42cf84d2a27fad3c48a90b90752c3ad6f Mon Sep 17 00:00:00 2001 From: HibiKier <775757368@qq.com> Date: Sat, 7 Sep 2024 01:50:24 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E8=87=AA=E6=A3=80html=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/template/check/main.css | 9 ++++-- resources/template/check/main.html | 16 +++------- zhenxun/builtin_plugins/check/__init__.py | 10 +++---- zhenxun/builtin_plugins/check/data_source.py | 31 ++++++++++++-------- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/resources/template/check/main.css b/resources/template/check/main.css index 2a0e207f8..97ee0c66a 100644 --- a/resources/template/check/main.css +++ b/resources/template/check/main.css @@ -161,12 +161,15 @@ body { .status-text { font-family: 'fzrzFont'; color: #EC859F; - height: 90px; - display: flex; + height: 185px; } .status-text-title { - height: 25%; + /* height: 25%; */ + display: flex; + /* justify-content: center; */ + align-items: center; + font-size: 14px; } .tip { diff --git a/resources/template/check/main.html b/resources/template/check/main.html index 7216e4bc5..00fffb85d 100644 --- a/resources/template/check/main.html +++ b/resources/template/check/main.html @@ -68,18 +68,10 @@
-
-

CPU

-

SYSTEM

-

VERSION

-

PLUGINS

-
-
-

{{data.brand_raw}}

-

{{data.system}}

-

{{data.version}}

-

{{data.plugin_count}} loaded

-
+

CPU         {{data.brand_raw}}

+

SYSTEM    {{data.system}}

+

VERSION   {{data.version}}

+

PLUGINS   {{data.plugin_count}} loaded

Create By Zhenxun
diff --git a/zhenxun/builtin_plugins/check/__init__.py b/zhenxun/builtin_plugins/check/__init__.py index a97ad0267..f4c4f89a1 100644 --- a/zhenxun/builtin_plugins/check/__init__.py +++ b/zhenxun/builtin_plugins/check/__init__.py @@ -1,15 +1,15 @@ -from nonebot.rule import to_me from nonebot.permission import SUPERUSER from nonebot.plugin import PluginMetadata -from nonebot_plugin_session import EventSession -from nonebot_plugin_htmlrender import template_to_pic +from nonebot.rule import to_me from nonebot_plugin_alconna import Alconna, Arparma, on_alconna +from nonebot_plugin_htmlrender import template_to_pic +from nonebot_plugin_session import EventSession +from zhenxun.configs.path_config import TEMPLATE_PATH +from zhenxun.configs.utils import PluginExtraData from zhenxun.services.log import logger from zhenxun.utils.enum import PluginType from zhenxun.utils.message import MessageUtils -from zhenxun.configs.utils import PluginExtraData -from zhenxun.configs.path_config import TEMPLATE_PATH from .data_source import get_status_info diff --git a/zhenxun/builtin_plugins/check/data_source.py b/zhenxun/builtin_plugins/check/data_source.py index d77429444..325e413a6 100644 --- a/zhenxun/builtin_plugins/check/data_source.py +++ b/zhenxun/builtin_plugins/check/data_source.py @@ -1,16 +1,16 @@ import platform -from pathlib import Path from dataclasses import dataclass +from pathlib import Path -import psutil import cpuinfo import nonebot -from pydantic import BaseModel +import psutil +from httpx import ConnectTimeout, NetworkError from nonebot.utils import run_sync -from httpx import NetworkError, ConnectTimeout +from pydantic import BaseModel -from zhenxun.services.log import logger from zhenxun.configs.config import BotConfig +from zhenxun.services.log import logger from zhenxun.utils.http_utils import AsyncHttpx BAIDU_URL = "https://www.baidu.com/" @@ -105,11 +105,17 @@ def get_system_info(self): "cpu_info": f"{self.cpu.usage}% - {self.cpu.freq}Ghz [{self.cpu.core} core]", "cpu_process": psutil.cpu_percent(), "ram_info": f"{self.ram.usage} / {self.ram.total} GB", - "ram_process": self.ram.usage / self.ram.total * 100, + "ram_process": ( + 0 if self.ram.total == 0 else (self.ram.usage / self.ram.total * 100) + ), "swap_info": f"{self.swap.usage} / {self.swap.total} GB", - "swap_process": self.swap.usage / self.swap.total * 100, + "swap_process": ( + 0 if self.swap.total == 0 else (self.swap.usage / self.swap.total * 100) + ), "disk_info": f"{self.disk.usage} / {self.disk.total} GB", - "disk_process": self.disk.usage / self.disk.total * 100, + "disk_process": ( + 0 if self.disk.total == 0 else (self.disk.usage / self.disk.total * 100) + ), } @@ -142,10 +148,11 @@ async def __get_network_info(): def __get_version() -> str | None: """获取版本信息""" - with open(VERSION_FILE, encoding="utf-8") as f: - if text := f.read(): - text.split(":")[-1] - return None + if VERSION_FILE.exists(): + with open(VERSION_FILE, encoding="utf-8") as f: + if text := f.read(): + return text.split(":")[-1] + return None async def get_status_info() -> dict: