Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use PyWeChatSpy to reply to Wechat automatically and take a pat?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to use PyWeChatSpy to automatically reply to Wechat to take a pat", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn how to use PyWeChatSpy to automatically reply to Wechat and take a pat.

1. First of all, let's prepare some emoticons. Here I chose the sand sculpture panda head.

2. Install version 2.8.0.133 of PC Wechat client (https://share.weiyun.com/5AwuXRG)

3. Install the Python3.8.3_x64 32-bit system (https://www.python.org/ftp/python/3.8.3/python-3.8.3-amd64.exe) students can go to the official website to download the 32-bit installation package.

4. Open cmd and enter pip install PyWeChatSpy to execute.

5. At this time, we need to encode. Create a new app.py file first.

First, the PyWeChatSpy module, the regular re module and the random random module re are introduced to match the message content, and random is used to randomly select the reply picture.

From PyWeChatSpy import WeChatSpyimport randomimport re

Then define a reply handling function my_parser

Def my_parser (data): pass

Then instantiate a WeChatSpy class

Spy = WeChatSpy (parser=my_parser)

Finally, the my_parser function processing logic is written.

If data ["type"] = = 5: # judgment is Wechat message data for msg in data ["data"]: # traversing Wechat message if msg ["msg_type"] = = 10000: # judgment is Wechat clap system prompt # because there are a lot of Wechat system messages, you need to further filter the clap prompt with regular matching message content # {'self': 0. 'msg_type': 10000,' wxid1': '179xxxxxx72,' content':'"Mandy's little head" patted you'} m = re.search ('. * "patted you', msg [" content "]) if m: # searched a matching string and judged it to be a beat image_path = f" images/ {random.randint (1) 7)} .jpg "# randomly select a reply picture spy.send_file (msg [" wxid1 "], image_path) # send the picture

Run the code

If _ _ name__ = ='_ main__': spy.run () # run the code

When it's done, if someone takes a picture of you again, whether it's a group chat or a private chat, you will automatically reply to the set picture.

The overall code is as follows:

From PyWeChatSpy import WeChatSpyimport randomimport redef my_parser (data): if data ["type"] = = 5: # determine that it is Wechat message data for msg in data ["data"]: # traverse Wechat message if msg ["msg_ typeot] = = 10000: # judge that Wechat clap the system prompt # because there are a lot of Wechat messages, so you need to use positive. Then match the content of the message to further filter the clap hint # {'self': 0 'msg_type': 10000,' wxid1': '179xxxxxx72,' content':'"Mandy's little head" patted you'} m = re.search ('. * "patted you', msg [" content "]) if m: # searched a matching string and judged it to be a beat image_path = f" images/ {random.randint (1) 7)} .jpg "# randomly select a reply image spy.send_file (msg [" wxid1 "], image_path) # send the picture spy = WeChatSpy (parser=my_parser) # instantiate the WeChatSpy class if _ _ name__ = ='_ main__': spy.run () # run the code

The app.py should be stored in the same place as the picture folder, otherwise it cannot be answered correctly, and the image address should be written as an absolute path.

At this point, I believe you have a deeper understanding of "how to use PyWeChatSpy to automatically reply to Wechat to take a pat". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report