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 reply to Wechat automatically through Python and take a pat with emojis?

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the relevant knowledge of "how to automatically reply to Wechat with emojis through Python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

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 WeChatSpy import random import 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 messages in Wechat system, 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

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 WeChatSpy import random import re def my_parser (data): if data ["type"] message = 5: # judge to be Wechat message data for msg in data ["data"]: # traverse Wechat message if msg ["msg_type"] = = 10000: # judge that Wechat clap the system prompt # because there are a lot of messages in Wechat system. Therefore, it is necessary to further filter the clap hint # {'self': 0 with the content of the regular matching message. 'msg_type': 10000,' wxid1': '179xxxxx72' atrochatroomy, 'content':' "Mandy's little head" patted you'} m = re.search ('. * 'patted you' Msg ["content"]) if m: # searched for a matching string and judged to take a shot image_path = f "images/ {random.randint (1,7)} .jpg" # randomly select a reply image spy.send_file (msg ["wxid1"] Image_path) # send picture spy = WeChatSpy (parser=my_parser) # instantiate the WeChatSpy class if _ _ name__ = ='_ main__': spy.run () # run the code

The app.py must be stored in the same place as the image folder, otherwise it cannot be answered correctly. For example, the image path D:\ images,app.py is stored in D:\ app.py, and the Chinese path is not supported.

This is the end of the content of "how to reply to Wechat automatically with emojis through Python". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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