- 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
73 lines
2.1 KiB
Python
73 lines
2.1 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""
|
||
wxauto 自动发消息示例
|
||
运行前请确保:1) 已安装依赖 pip install -e .
|
||
2) 电脑已登录微信 3.9 版本,且主窗口已打开
|
||
"""
|
||
import sys
|
||
import time
|
||
|
||
# 确保能导入当前项目的 wxauto(以脚本所在目录为项目根)
|
||
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
|
||
|
||
|
||
def send_to_one(wx, who: str, msg: str):
|
||
"""给指定联系人/群发一条消息"""
|
||
ret = wx.SendMsg(msg, who=who)
|
||
if ret:
|
||
print(f"[成功] 已向 [{who}] 发送: {msg}")
|
||
else:
|
||
print(f"[失败] 发送给 [{who}] 失败: {ret}")
|
||
return ret
|
||
|
||
|
||
def send_to_many(wx, items: list, interval_sec: float = 2.0):
|
||
"""
|
||
批量发消息
|
||
items: [(who, msg), ...] 或 [{"who": "张三", "msg": "你好"}, ...]
|
||
interval_sec: 每条消息间隔秒数,避免操作过快
|
||
"""
|
||
for i, item in enumerate(items):
|
||
if isinstance(item, (list, tuple)):
|
||
who, msg = item[0], item[1]
|
||
else:
|
||
who, msg = item["who"], item["msg"]
|
||
send_to_one(wx, who, msg)
|
||
if i < len(items) - 1:
|
||
time.sleep(interval_sec)
|
||
|
||
|
||
def main():
|
||
print("正在连接微信...")
|
||
try:
|
||
wx = WeChat()
|
||
except Exception as e:
|
||
print("连接失败,请确保:")
|
||
print(" 1. 已安装依赖: pip install -e .")
|
||
print(" 2. 微信 3.9 已登录并保持主窗口打开")
|
||
print(f" 错误: {e}")
|
||
return
|
||
|
||
# ========== 示例1:给一个人发一条消息 ==========
|
||
# 把 "文件传输助手" 改成你要发的联系人/群名
|
||
who = "文件传输助手"
|
||
msg = "这是一条由 wxauto 自动发送的消息"
|
||
send_to_one(wx, who, msg)
|
||
|
||
# ========== 示例2:批量发(可注释掉上面示例1,只保留下面) ==========
|
||
# send_to_many(wx, [
|
||
# ("文件传输助手", "第一条"),
|
||
# ("文件传输助手", "第二条"),
|
||
# ], interval_sec=2.0)
|
||
|
||
print("执行完毕。")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|