Merge pull request #614 from InfinityPacer/main

This commit is contained in:
jxxghp
2024-12-26 07:00:45 +08:00
committed by GitHub
2 changed files with 15 additions and 5 deletions

View File

@@ -8,6 +8,7 @@
"author": "lightolly,jxxghp",
"level": 2,
"history": {
"v1.5": "修复了发送增量通知失败等一些问题",
"v1.4.1": "支持数据刷新时发送消息通知",
"v1.3": "远程刷新命令移植到主程序",
"v1.2": "继续修复增量数据统计问题",

View File

@@ -3,13 +3,16 @@ from datetime import datetime, timedelta
from threading import Lock
from typing import Optional, Any, List, Dict, Tuple
import pytz
from app.helper.sites import SitesHelper
from apscheduler.schedulers.background import BackgroundScheduler
from app import schemas
from app.chain.site import SiteChain
from app.core.config import settings
from app.core.event import eventmanager, Event
from app.db.models.siteuserdata import SiteUserData
from app.db.site_oper import SiteOper
from app.helper.sites import SitesHelper
from app.log import logger
from app.plugins import _PluginBase
from app.schemas.types import EventType, NotificationType
@@ -28,7 +31,7 @@ class SiteStatistic(_PluginBase):
# 插件图标
plugin_icon = "statistic.png"
# 插件版本
plugin_version = "1.4.1"
plugin_version = "1.5"
# 插件作者
plugin_author = "lightolly,jxxghp"
# 作者主页
@@ -48,6 +51,7 @@ class SiteStatistic(_PluginBase):
_onlyonce: bool = False
_dashboard_type: str = "today"
_notify_type = ""
_scheduler = None
def init_plugin(self, config: dict = None):
self.siteoper = SiteOper()
@@ -66,7 +70,12 @@ class SiteStatistic(_PluginBase):
if self._onlyonce:
config["onlyonce"] = False
self.sitechain.refresh_userdatas()
self._scheduler = BackgroundScheduler(timezone=settings.TZ)
self._scheduler.add_job(self.sitechain.refresh_userdatas, "date",
run_date=datetime.now(tz=pytz.timezone(settings.TZ)) + timedelta(seconds=3),
name="站点数据统计服务")
self._scheduler.print_jobs()
self._scheduler.start()
self.update_config(config=config)
def get_state(self) -> bool:
@@ -226,8 +235,8 @@ class SiteStatistic(_PluginBase):
updated_date = today_data_dict[site].updated_day
if self._notify_type == "inc" and yesterday_data_dict.get(site):
upload -= int(yesterday_data[site].get("upload") or 0)
download -= int(yesterday_data[site].get("download") or 0)
upload -= int(yesterday_data_dict[site].upload or 0)
download -= int(yesterday_data_dict[site].download or 0)
if updated_date and updated_date != today_date:
updated_date = f"{updated_date}"