- Add wxauto package with WeChat UI automation and message handling capabilities - Implement job_extractor.py for automated job posting extraction from WeChat groups - Add job_extractor_gui.py providing graphical interface for job extraction tool - Create comprehensive documentation in Chinese covering GUI usage, multi-group support, and quick start guides - Add build configuration files (build_exe.py, build_exe.spec) for packaging as standalone executable - Include utility scripts for WeChat interaction (auto_send_msg.py, get_history.py, receive_file_transfer.py) - Add project configuration files (pyproject.toml, setup.cfg, requirements.txt) - Include test files (test_api.py, test_com_fix.py) for API and compatibility validation - Add Apache 2.0 LICENSE and comprehensive README documentation - Configure .gitignore to exclude build artifacts, logs, and temporary files
70 lines
2.2 KiB
Python
70 lines
2.2 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""
|
||
获取「文件传输助手」历史记录并输出到控制台
|
||
运行前请确保:1) 已安装依赖 pip install -e .
|
||
2) 电脑已登录微信 3.9 版本,且主窗口已打开
|
||
"""
|
||
import sys
|
||
import os
|
||
|
||
_script_dir = os.path.dirname(os.path.abspath(__file__))
|
||
if _script_dir not in sys.path:
|
||
sys.path.insert(0, _script_dir)
|
||
|
||
from wxauto import WeChat
|
||
|
||
# 要获取历史的聊天(可改成其他好友/群名)
|
||
TARGET_CHAT = "文件传输助手"
|
||
# 向上加载更多页数(每页约一批消息),0 表示只取当前已加载的
|
||
LOAD_MORE_PAGES = 10
|
||
|
||
|
||
def format_msg(msg, index: int):
|
||
"""单条消息格式化为一行输出"""
|
||
msg_type = getattr(msg, "type", "text")
|
||
content = getattr(msg, "content", "")
|
||
sender = getattr(msg, "sender_remark", "") or getattr(msg, "sender", "")
|
||
content = (content or "").replace("\n", " ").strip()
|
||
if msg_type != "text":
|
||
content = f"[{msg_type}] " + (content or "(非文本)")
|
||
return f" {index}. [{sender}] {content}"
|
||
|
||
|
||
def main():
|
||
print("正在连接微信...")
|
||
try:
|
||
wx = WeChat()
|
||
except Exception as e:
|
||
print("连接失败,请确保:")
|
||
print(" 1. 已安装依赖: pip install -e .")
|
||
print(" 2. 微信 3.9 已登录并保持主窗口打开")
|
||
print(f" 错误: {e}")
|
||
return
|
||
|
||
print(f"正在切换到「{TARGET_CHAT}」并获取历史记录...\n")
|
||
if not wx.ChatWith(TARGET_CHAT):
|
||
print(f"无法切换到「{TARGET_CHAT}」,请检查名称是否正确")
|
||
return
|
||
|
||
# 向上滚动加载更多历史(可选)
|
||
if LOAD_MORE_PAGES > 0:
|
||
for i in range(LOAD_MORE_PAGES):
|
||
ret = wx.LoadMoreMessage(interval=0.3)
|
||
if not ret:
|
||
break
|
||
|
||
msgs = wx.GetAllMessage()
|
||
if not msgs:
|
||
print("当前没有获取到任何消息。")
|
||
return
|
||
|
||
# 列表通常是时间正序(从旧到新),直接按序输出
|
||
print(f"---------- 「{TARGET_CHAT}」 历史记录(共 {len(msgs)} 条)----------")
|
||
for i, msg in enumerate(msgs, 1):
|
||
print(format_msg(msg, i))
|
||
print("---------- 结束 ----------")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|