In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use PyWeChatSpy to realize automatic reply to WeChat for a shot". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian and go deep into it slowly to study and learn "how to use PyWeChatSpy to realize automatic reply to WeChat for a shot"!
1. First of all, we prepare some emoticons. Here I chose the sand eagle panda head.
2. Install PC WeChat client version 2.8.0.133 (https://share.weiyun.com/5AwuXRG)
3. Students who install Python3.8.3_x64 32-bit system (https://www.python.org/ftp/python/3.8.3/python-3.8.3-amd64.exe) can go to the official website to download the 32-bit installation package themselves.
4. Open cmd and enter pip install PyWeChatSpy to execute
5, this time we need to code, first create a new app.py file
PyWeChatSpy module, regular re module and random re module are introduced to match message content, random is used to randomly select reply pictures
from PyWeChatSpy import WeChatSpy import random import re
Then define a reply processing function my_parser
def my_parser(data): pass
Then instantiate a WeChatSpy class
spy = WeChatSpy(parser=my_parser)
Finally write my_parser function processing logic
if data["type"] == 5: #Determine WeChat message data for msg in data["data"]: #Traverse WeChat messages if msg["msg_type"] == 10000: #Determine whether it is WeChat, take a shot, system prompt #Because there are many messages in WeChat system, it is necessary to further filter the beat prompt with regular matching message content # {'self': 0, 'msg_type': 10000, 'wxid1': '179xx72@chatroom',' content':'Mandy's little head patted you'} m = re.search('".* "I patted you', msg["content"]) if m: #Search for a matching string and judge it as a beat image_path = f"images/{random.randint(1, 7)}.jpg" #Choose a random image to reply to spy.send_file(msg["wxid1"], image_path) #Send image
run code
if __name__ == '__main__': spy.run () #Run Code
When you're done, if someone takes pictures of you, whether it's Group chats or private chats, they'll automatically reply to the set pictures.
The overall code is as follows:
from PyWeChatSpy import WeChatSpy import random import re def my_parser(data): if data["type"] == 5: #Determine WeChat message data for msg in data["data"]: #Traverse WeChat messages if msg["msg_type"] == 10000: #Determine whether it is WeChat, take a shot, system prompt #Because there are many messages in WeChat system, it is necessary to further filter the beat prompt with regular matching message content # {'self': 0, 'msg_type': 10000, 'wxid1': '179xx72@chatroom',' content':'Mandy's little head patted you'} m = re.search('".* "I patted you', msg["content"]) if m: #Find a matching string and judge it as a beat image_path = f"images/{random.randint(1, 7)}.jpg" #Choose a random image to reply to spy.send_file(msg["wxid1"], image_path) #Send image spy = WeChatSpy(parser=my_parser) #Instantiate WeChatSpy class if __name__== '__main__': spy.run () #Run Code
App.py must be stored in the same place as the image folder, otherwise it cannot be correctly replied. For example, the image path D:\images,app.py storage path D:\app.py does not support Chinese path temporarily.
Thank you for reading, the above is the content of "how to use PyWeChatSpy to realize automatic reply WeChat take a shot". After learning this article, I believe everyone has a deeper understanding of how to use PyWeChatSpy to realize automatic reply WeChat take a shot. The specific use situation still needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.