Files
jianli-boss/client/debug_activate_dry.py
T
2026-08-26 19:32:21 +08:00

62 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""
端到端试跑验证 Activator(dry_run=True 只识别、绝不发送):
扫描左侧列表 → 状态过滤(送达/未读)→ 可信点击进入会话 →
读取我发出的最后一条消息 → 相似度比对 → 命中仅记录日志。
用法:python -m client.debug_activate_dry
日志:client/data/debug/activate_dry.log + 控制台
"""
import time
from pathlib import Path
from loguru import logger
from client.browser.manager import BrowserManager
from client.browser.activator import Activator, similarity
OUT = Path(__file__).resolve().parent / "data" / "debug" / "activate_dry.log"
# 实测账号中真实的打招呼语(用于匹配条件)
MATCH_TEXT = ("您好 我对这份工作很感兴趣也很有信心完成相关工作,"
"想跟您沟通一下细节,请问您方便聊聊吗。")
def main():
OUT.parent.mkdir(parents=True, exist_ok=True)
if OUT.exists():
OUT.unlink()
logger.add(str(OUT), encoding="utf-8", level="DEBUG")
# 相似度函数单元自检(纯函数,无浏览器依赖)
cases = [
(MATCH_TEXT, MATCH_TEXT, 1.0),
(MATCH_TEXT, MATCH_TEXT[:-3], None), # 少几个字,应明显低于 1
("好的", MATCH_TEXT, None), # 完全不相关,应远低于阈值
("", MATCH_TEXT, 0.0),
]
for a, b, expect in cases:
r = similarity(a, b)
line = f"[自检] similarity={r:.3f} | a={a[:20]!r} b={b[:20]!r}"
if expect is not None:
line += f" expect={expect}"
print(line.encode("utf-8", "replace").decode("utf-8"), flush=True)
manager = BrowserManager()
act = Activator(manager)
act.start(match_text=MATCH_TEXT, threshold=0.8,
reply_message="[试跑] 本消息不会真的发送",
max_count=3, dry_run=True)
# 等任务跑完(最长 3 分钟)
for _ in range(180):
if not act.is_running:
break
time.sleep(1)
print(f"[结果] stats={act.stats}", flush=True)
print(f"[完成] 详细日志见 {OUT}", flush=True)
if __name__ == "__main__":
main()