72 lines
2.2 KiB
Python
72 lines
2.2 KiB
Python
"""用 session_name 模块跑一遍真实窗口:标题和列表各行的昵称、md5、耗时。"""
|
|
import os
|
|
import sys
|
|
import time
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
import numpy as np # noqa: E402
|
|
import session_name # noqa: E402
|
|
import wechat_bot as bot_module # noqa: E402
|
|
|
|
|
|
def main() -> None:
|
|
bot = bot_module.WeChatBot()
|
|
bot.safe_window_mode = True
|
|
bot.auto_activate_window = False
|
|
if not bot.connect(activate=False, wait_if_missing=False):
|
|
print("[-] 未挂载到企业微信窗口")
|
|
return
|
|
|
|
reader = session_name.NameReader()
|
|
if not reader.available:
|
|
print("[-] OCR 引擎不可用")
|
|
return
|
|
|
|
scale = max(0.75, float(bot.scale or 1.0))
|
|
full = bot._capture_full_window()
|
|
x1 = int(bot._list_x + bot._list_w)
|
|
|
|
print("=" * 78)
|
|
print("当前打开的会话(聊天标题)")
|
|
print("=" * 78)
|
|
panel = np.ascontiguousarray(
|
|
full[int(20 * scale):int(78 * scale),
|
|
x1 + int(8 * scale):x1 + int(600 * scale), :3]
|
|
)
|
|
start = time.perf_counter()
|
|
name = reader.read(panel)
|
|
cost = (time.perf_counter() - start) * 1000
|
|
print(f" 昵称 {name!r}")
|
|
print(f" 会话ID {session_name.session_id_for(name)}")
|
|
print(f" 耗时 {cost:.0f} ms")
|
|
|
|
print()
|
|
print("=" * 78)
|
|
print("会话列表")
|
|
print("=" * 78)
|
|
listing = bot.capture_session_list()
|
|
item_h = max(1, int(bot.session_item_h))
|
|
rows = max(1, listing.shape[0] // item_h)
|
|
total = 0.0
|
|
for index in range(min(rows, 10)):
|
|
y0 = index * item_h
|
|
panel = np.ascontiguousarray(
|
|
listing[y0 + int(item_h * 0.14):y0 + int(item_h * 0.50),
|
|
int(72 * scale):int(310 * scale), :3]
|
|
)
|
|
start = time.perf_counter()
|
|
name = reader.read(panel)
|
|
cost = (time.perf_counter() - start) * 1000
|
|
total += cost
|
|
sid = session_name.session_id_for(name)
|
|
print(f" 第 {index} 行 {cost:5.0f} ms {name!r:<24} {sid[:16] if sid else '(读不到)'}")
|
|
print(f" 整列共 {total:.0f} ms")
|
|
|
|
print()
|
|
print(f"已认识的昵称: {reader.known_names()}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|