feat: 故障推送 / 公需课自动重学 / 插件解耦,发版 v0.0.8

体检修复:启动日志不再打印 AUTH_TOKEN、密钥可清空、推送失败不占整段冷却、目录名与文案统一成 plugins/。
This commit is contained in:
study-tool
2026-11-01 17:47:22 +08:00
parent 491fd08c1e
commit aa48145557
114 changed files with 7779 additions and 3302 deletions
@@ -0,0 +1,64 @@
"""莞易学插件常量:站点地址、登录授权入口、课程板块、页面快照目录。
只给 `plugins/guanyixue/` 内部用;其它平台各自在自己的插件目录里放常量。
"""
import os
import re
import shutil
from study_tool.config import DATA
def _find_node():
"""Locate a node.exe: $NODE_BIN > PATH > common install dirs."""
for c in [os.environ.get("NODE_BIN"), shutil.which("node"), shutil.which("node.exe"),
r"D:\Software\devlopSoftware\Node\24.16.0\node.exe",
r"C:\Program Files\nodejs\node.exe",
r"C:\Program Files (x86)\nodejs\node.exe"]:
if c and os.path.exists(c):
return c
return "node"
NODE = _find_node()
DESENC = os.path.join(os.path.dirname(os.path.abspath(__file__)), "script", "desenc.js") # 随插件目录走
UA = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/154.0.0.0 Safari/537.36 Edg/154.0.0.0")
JSPX = "https://jspx.dgjy.net"
TPASS = "https://tyyh.dgjy.net/tpass"
# 表单提交带上来源头,和浏览器一致(该站有 WAF,字段异常会直接 403)
LOGIN_HEADERS = {"Referer": TPASS + "/login", "Origin": "https://tyyh.dgjy.net"}
AUTHORIZE = ("https://tyyh.dgjy.net/tpass/oauth2.0/authorize?client_id=wpxtgl&scope=all"
"&response_type=code&state=random&redirect_uri=https%3A%2F%2Fdj.dgjy.net%2Fhomepage"
"%2Fremote%2Fopenapi%2Fdgwjt%2Flogin%3Furl%3Dhttps%3A%2F%2Fjspx.dgjy.net%2Ftstudy"
"%2Fpassport%2Flogin.action")
EP_STUDY = JSPX + "/train/trainee/courseware-studyTimeUpdate.action"
# 新版培训平台(莞易学/study.dgjy.net)的课程接口。2026 年起的「慕课」课程不再
# 用 jspx 的 tier-tree 页面,而是 Vue SPA + /train/course/front/* 这组 JSON 接口。
TRAIN_AUTHORIZE_PATH = ("/oauth2.0/authorize?client_id=gyx&scope=all&response_type=code"
"&state=random&redirect_uri=https%3A%2F%2Fstudy.dgjy.net%2F%23%2Flogin%2Fback")
STUDY = os.environ.get("STUDY_BASE", "https://study.dgjy.net").rstrip("/")
DEBUG_DIR = os.path.join(DATA, "debug") # 页面快照的兜底目录(正常存 SQLite 的 snapshots 表)
os.makedirs(DEBUG_DIR, exist_ok=True)
HEX32 = re.compile(r"^[0-9A-Fa-f]{32}$")
# OAuth 授权码:tpass 发的是 ST-369516-xxxx-tpass,带连字符,不能只认 [0-9A-Za-z]
CODE_RE = re.compile(r"(?:[?#&]|\b)code=([0-9A-Za-z._\-]{6,128})")
# 「我的课程」的三个板块 -> 各自的 AJAX 列表接口与 courseType
COURSE_SECTIONS = [
("在学课程", "/train/trainee/studyingCourse.action", "studying"),
("助学课程", "/train/assist/assistanceCourse.action", "assistance"),
("督学课程", "/train/inspect/inspectingCourse.action", "inspecting"),
]
# 每个板块的三种状态(页面上是「进行中 / 未开始 / 已结束」三个页签)
PLAN_STATUS = [
("进行中", "TAKING_PLAN"),
("未开始", "NO_BEGAIN_PLAN"),
("已结束", "FINISHED_PLAN"),
]
# 只有这两种状态还能进去学;已结束的只能查看
STUDYABLE_STATUS = {"TAKING_PLAN", "NO_BEGAIN_PLAN"}