76 lines
3.3 KiB
Python
76 lines
3.3 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""携程数据导出 - webhost 场景插件(XQ0077)
|
||
|
||
流程(纯接口,不使用浏览器):
|
||
1) 登录深大/lotsmall 管理端(图片验证码 OCR + RSA 密码加密;token 缓存复用);
|
||
2) statisticsSupport(取报表接入参数)→ verifySaasAuthCode(换 JWT)→ preview(取元数据);
|
||
3) searchFilter 先查询判有无数据,无数据直接跳过;有数据才 newExport 下载 xlsx
|
||
→ 检票员检票报表_YYYYMMDD_HHMMSS.xlsx。
|
||
"""
|
||
import os
|
||
|
||
from webhost.backend.plugins.base import PLUGINS, ScenePlugin
|
||
|
||
from . import config
|
||
from .data import lotsmall_report
|
||
|
||
|
||
class TicketInspectorReportPlugin(ScenePlugin):
|
||
id = "xq0077"
|
||
name = "携程数据导出"
|
||
version = "1.0.2"
|
||
description = ("深大/lotsmall 管理端「检票员检票报表」导出:账密自动登录(图片验证码 OCR + RSA 密码加密),"
|
||
"纯接口查询判有无数据后导出 xlsx,日期口径固定昨天 00:00:00 ~ 今天 23:59:59")
|
||
platform = "" # 管理端自带账密登录,不使用底座共享登录态
|
||
uses_month = False
|
||
capabilities = ["xq0077"]
|
||
permissions = {"platforms": []}
|
||
# 与 plugin.json.fields 一致
|
||
fields = {
|
||
"account": {"type": "string", "title": "登录账号", "default": "",
|
||
"description": "深大/lotsmall 管理端账号(手机号或用户名)"},
|
||
"password": {"type": "string", "title": "登录密码", "default": "",
|
||
"description": "管理端登录密码(明文存本地配置)"},
|
||
"save_dir": {"type": "string", "title": "保存目录", "default": "",
|
||
"description": "留空=D:\\资料\\财务\\携程数据导出"},
|
||
"debug_mode": {"type": "boolean", "title": "调试日志", "default": False},
|
||
}
|
||
|
||
def run(self, fields, ctx) -> dict:
|
||
fields = fields or {}
|
||
config.set_log(ctx.log)
|
||
config.set_progress(ctx.progress)
|
||
config.set_debug(bool(fields.get("debug_mode")))
|
||
|
||
account = str(fields.get("account") or "").strip()
|
||
password = str(fields.get("password") or "").strip()
|
||
if not (account and password):
|
||
raise RuntimeError("请在插件界面填写深大/lotsmall 管理端的登录账号与密码")
|
||
|
||
save_dir = str(fields.get("save_dir") or "").strip().strip('"') or config.default_output_dir()
|
||
os.makedirs(save_dir, exist_ok=True)
|
||
begin, end = config.date_window()
|
||
ctx.log(f"日期区间:{begin} ~ {end}")
|
||
ctx.log(f"保存目录:{save_dir}")
|
||
|
||
result = lotsmall_report.run_export(account, password, save_dir)
|
||
config.progress(100)
|
||
|
||
total = int(result.get("total") or 0)
|
||
file = result.get("file") or ""
|
||
date_range = f"{begin} ~ {end}"
|
||
if total <= 0 or not file:
|
||
return {
|
||
"summary": f"无数据,未导出({date_range})",
|
||
"detail": {"range": date_range, "total": 0, "save_dir": save_dir},
|
||
"path": save_dir,
|
||
}
|
||
return {
|
||
"summary": f"检票员检票报表导出完成:{os.path.basename(file)}({total} 条)",
|
||
"detail": {"range": date_range, "total": total, "file": file, "save_dir": save_dir},
|
||
"path": file,
|
||
}
|
||
|
||
|
||
PLUGINS.append(TicketInspectorReportPlugin())
|