Play WeChat with Python
Possible application scenarios
Message forwarding between multiple groups WeChat group limit (500 people)
Customer Service Robot
Social & Fun
Automatic clock-in and clock-out calendar reminders, etc.
Information promotion (news, products, advertising, etc.)
Monitor Alerts
Unsupported Features
Payment Related - Red Packets, Transfers, Receipts, etc. are not supported
@ someone in a group chat - yes, Web WeChat doesn't alert you when you're @ someone either
Send business cards - but can be forwarded via send_raw_msg()
Send share link - also not forwarding
Sending voice messages
Circle of Friends Related
Unable to delete friends and unfollow public numbers
Risks and shortcomings
There is a chance that you will be restricted from logging in, mainly to Web WeChat (but not to other platforms such as mobile).
Newly registered WeChat signal cannot login directly to Web WeChat
There is a subsequent risk that the web version of WeChat will be discontinued
Module Features
Send text, pictures, videos, files
Search by keywords or user attributes Friends, group chat, group members, etc.
Get nickname, notes, gender, region, etc. of friends/group members
Add friends, create groups, invite to groups, move out of groups
easy to get started
# Import modules
fromwxpyimport
# Initialize the bot, scan the code and log in
bot=Bot()
# Search for names containing " swim or swim not" of male Shenzhen friends
my_friend=bot.friends().search(' swim or swim not',sex=MALE,city=" Shenzhen")[]
# Send text to a friend
my_friend.send('Hello WeChat!')
# Sending pictures
my_friend.send_image('my_picture.jpg')
# Search for names containing " swim or swim not" of male Shenzhen friends
my_friend=bot.friends().search(' swim or swim not',sex=MALE,city=" Shenzhen")[]
# Send text to a friend
my_friend.send('Hello WeChat!')
# Sending pictures
my_friend.send_image('my_picture.jpg')
# Print messages from other friends, group chats and public
@bot.register()
defprint_others(msg):
print(msg)
# Reply to my_friend's message (priority match after registered function!)
@bot.register(my_friend)defreply_my_friend(msg):
return'received:{}({})'.format(msg.text,msg.type)
# Automatically accept new friend requests
@bot.register(msg_types=FRIENDS)
defauto_accept_friends(msg):
# Accept friend request new_friend=msg.card.accept() # Send message to new friend
new_friend.send(' (onom.) laughing out loud, I automatically accepted your friend request.')
# Go to the Python command line, keep the program running
embed()
# Or just blocking threads
# bot.join()
this text
Introducing some usage scenarios, unsupported features, and risks and pitfalls of pywx.