Attention!
Some common scenarios
All in all, it can be used to automate various WeChat personal accounts.
wxpy supports Python 3.4-3.6, and version 2.7
Replace "pip" in the command below with "pip3" or "pip2" to ensure installation to the corresponding Python version
pip install -U wxpy
pip install -U wxpy -i " https://pypi.doubanio.com/simple/ "
Log in to WeChat:
# 导入模块
from wxpy import *
# 初始化机器人,扫码登陆
bot = Bot ()
Find friends:
# 搜索名称含有 "游否" 的男性深圳好友
my_friend = bot . friends (). search ( '游否' , sex = MALE , city = "深圳" )[ 0 ]
Send message:
# 发送文本给好友
my_friend . send ( 'Hello WeChat!' )
# 发送图片
my_friend . send_image ( 'my_picture.jpg' )
Automatically respond to various messages:
# 打印来自其他好友、群聊和公众号的消息
@ bot . register ()
def print_others ( msg ):
print ( msg )
# 回复 my_friend 的消息 (优先匹配后注册的函数!)
@ bot . register ( my_friend )
def reply_my_friend ( msg ):
return 'received: {} ({})' . format ( msg . text , msg . type )
# 自动接受新的好友请求
@ bot . register ( msg_types = FRIENDS )
def auto_accept_friends ( msg ):
# 接受好友请求
new_friend = msg . card . accept ()
# 向新的好友发送消息
new_friend . send ( '哈哈,我自动接受了你的好友请求' )
Stay logged in/running:
# 进入 Python 命令行、让程序保持运行
embed ()
# 或者仅仅堵塞线程
# bot.join()
Comprehensive object-based interface, more elegant calling
The default multi-threaded response message, faster reply
Contains useful components such as chatbots and mutual friends
Just two lines of code, use WeChat to receive warnings in other projects
Pleasant exploration and debugging, no need to make changes
The original interface of itchat can be mixed with
Of course, it also covers various common basic functions:
- Send texts, pictures, videos, files
- Search friends, group chats, group members, etc. by keywords or user attributes
- Get the nickname, notes, gender, region and other information of friends/group members
- Add friends, create a group, invite to the group, move out of the group
http://wxpy.readthedocs.io
https://github.com/youfou/wxpy/releases
https://github.com/youfou/wxpy