77 lines
3.0 KiB
Python
77 lines
3.0 KiB
Python
"""身份会不会随时间漂?这是改用昵称之后最要命的失败方式。
|
||
|
||
列表里的时间戳一直在走(「1分钟前」→「12:08」)。如果它混进了昵称的裁剪框,
|
||
同一个人过一会儿就换一个 md5,任务永远对不上。隔一段时间连读几轮,看 ID 变不变;
|
||
顺带对照聊天标题读出来的名字,是否和列表行算出同一个身份。
|
||
"""
|
||
import os
|
||
import sys
|
||
import time
|
||
|
||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||
|
||
import wechat_bot as bot_module # noqa: E402
|
||
|
||
ROUNDS = 4
|
||
GAP_SECONDS = 20
|
||
|
||
|
||
def main() -> None:
|
||
bot = bot_module.WeChatBot()
|
||
bot.safe_window_mode = True
|
||
bot.auto_activate_window = True
|
||
if not bot.connect(activate=False, wait_if_missing=True):
|
||
print("[-] 未挂载到企业微信窗口")
|
||
return
|
||
if not bot._ensure_visible():
|
||
print("[-] 企业微信主界面未还原")
|
||
return
|
||
|
||
history = {}
|
||
for attempt in range(ROUNDS):
|
||
listing = bot.capture_session_list()
|
||
item_h = max(1, int(bot.session_item_h))
|
||
rows = max(1, listing.shape[0] // item_h)
|
||
for index in range(min(rows, 8)):
|
||
center = index * item_h + item_h // 2
|
||
name = bot._row_display_name(listing, center, row_center=True)
|
||
fp = bot._session_fingerprint(listing, center, row_center=True)
|
||
history.setdefault(index, []).append((name, bot.session_id_of(fp)))
|
||
print(f" 第 {attempt + 1}/{ROUNDS} 轮已采集({time.strftime('%H:%M:%S')})")
|
||
if attempt < ROUNDS - 1:
|
||
time.sleep(GAP_SECONDS)
|
||
|
||
print()
|
||
print(" 行 昵称 结果")
|
||
print(" " + "-" * 70)
|
||
unstable = 0
|
||
for index, samples in sorted(history.items()):
|
||
ids = {sid for _name, sid in samples}
|
||
names = {name for name, _sid in samples}
|
||
first = samples[0][0] or "(读不到)"
|
||
if len(ids) == 1:
|
||
verdict = f"稳定 {samples[0][1][:16]}…"
|
||
else:
|
||
unstable += 1
|
||
verdict = f"★漂移★ 读到过 {names}"
|
||
print(f" {index:<3} {first:<20} {verdict}")
|
||
|
||
print()
|
||
title_name = bot._open_chat_display_name()
|
||
title_fp = bot._fp_from_name(title_name)
|
||
print(f" 聊天标题读到: {title_name!r} → {bot.session_id_of(title_fp)}")
|
||
listing = bot.capture_session_list()
|
||
selected_y = bot.detect_selected_row(listing)
|
||
if selected_y >= 0:
|
||
row_fp = bot._session_fingerprint(listing, selected_y, row_center=True)
|
||
row_name = bot._row_display_name(listing, selected_y, row_center=True)
|
||
print(f" 选中行读到: {row_name!r} → {bot.session_id_of(row_fp)}")
|
||
print(f" 标题与列表行是同一个身份?{bot._session_fp_matches(title_fp, row_fp)}")
|
||
|
||
print()
|
||
print("★ 漂移行数:" if unstable else "全部稳定,没有一行的身份随时间变化。", unstable or "")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|