feat: 每月定时开始学习并改为本地计算心跳摘要
This commit is contained in:
+12
-17
@@ -14,7 +14,6 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import contextlib
|
||||
import hashlib
|
||||
import json
|
||||
import logging
|
||||
import random
|
||||
@@ -25,12 +24,12 @@ from datetime import datetime, timezone
|
||||
import httpx
|
||||
from sqlalchemy import select
|
||||
|
||||
from euniv.client import EUNIV, STUDY_API, USER_AGENT, EunivClient, SessionExpired
|
||||
from euniv.client import EUNIV, STUDY_API, USER_AGENT, EunivClient, SessionExpired, study_encryption
|
||||
from euniv.models import Account, Course
|
||||
from euniv.study_window import window_open
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
_SCORM_MD5_KEY = "60db8c0a-72d8-4b8f-bb45-c4c3f29a2696"
|
||||
_MAX_CONCURRENT_USERS = 8
|
||||
_MAX_COURSE_PER_USER = 1
|
||||
_HOURS_REFRESH_SECONDS = 300.0
|
||||
@@ -102,7 +101,7 @@ def _jitter(seconds: int) -> float:
|
||||
|
||||
|
||||
def _scorm_md5(body_json: str) -> str:
|
||||
return hashlib.md5((body_json + _SCORM_MD5_KEY).encode("utf-8")).hexdigest()
|
||||
return study_encryption(body_json)
|
||||
|
||||
|
||||
def _parse_minutes(value: str) -> int:
|
||||
@@ -247,18 +246,7 @@ class StudySession:
|
||||
return resp.json()
|
||||
|
||||
async def get_encrypt_request(self, body_json: str) -> str:
|
||||
assert self._client is not None
|
||||
resp = await self._client.post(
|
||||
f"{EUNIV}/kng/services/KngComService.svc/GetEncryptRequest",
|
||||
json={"body": body_json},
|
||||
headers={"Content-Type": "text/json", "User-Agent": USER_AGENT},
|
||||
)
|
||||
data = resp.json()
|
||||
if isinstance(data, str):
|
||||
data = json.loads(data)
|
||||
if data.get("Status") == "OK":
|
||||
return str(data["Data"])
|
||||
raise RuntimeError(f"GetEncryptRequest 失败: {data}")
|
||||
return study_encryption(body_json)
|
||||
|
||||
async def submit_video_heartbeat(self, kid: str, pkg_id: str,
|
||||
study_time: int, view_schedule: int) -> dict:
|
||||
@@ -611,7 +599,11 @@ class AutoStudyWorker:
|
||||
courses = db.scalars(select(Course).order_by(Course.title)).all()
|
||||
course_list = [(c.path, c.title, c.kind) for c in courses]
|
||||
eligible = []
|
||||
waiting = 0
|
||||
for row in users:
|
||||
if not window_open(row):
|
||||
waiting += 1
|
||||
continue
|
||||
target = row.monthly_target or 600
|
||||
current = _parse_minutes(row.month_hours)
|
||||
if target > 0 and current < target:
|
||||
@@ -628,7 +620,10 @@ class AutoStudyWorker:
|
||||
return
|
||||
|
||||
if not eligible:
|
||||
_set_status(running=False, message="所有用户已达标或无有效凭据")
|
||||
if waiting:
|
||||
_set_status(running=False, message="未到开始时间或已达标")
|
||||
else:
|
||||
_set_status(running=False, message="所有用户已达标或无有效凭据")
|
||||
return
|
||||
|
||||
_set_status(running=True, message=f"本轮 {len(eligible)} 个用户")
|
||||
|
||||
Reference in New Issue
Block a user