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 Python to restore recalled Wechat messages

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

In this issue, the editor will bring you about how to use Python to restore withdrawn Wechat messages. The article is rich in content and analyzes and narrates from a professional point of view. I hope you can get something after reading this article.

I woke up early in the morning to find three messages from the goddess last night, but they all showed that they had been withdrawn. OMG, what did I miss? The photo of a beautiful girl in the group has been withdrawn, but I can't see it if I want to see it! The classic quotation shared by the boss in the group has been withdrawn, and I feel that I have missed 100 million! What shall I do? With the omnipotent Python, you can send these withdrawn messages to your Wechat, taking you to the pinnacle of your life.

Project environment

Language: Python3

Editor: Pycharm

Guide package

Itchat: the third-party library that controls Wechat

I believe you are no stranger to this library. The Python robot you wrote earlier chatted with you Python regularly to the goddess. Good morning the wxpy library used in the two articles is encapsulated on the basis of the itchat library.

Effect display

The types of withdrawal messages shown in the following screenshots are text message, Wechat's own facial expression, picture, voice, location map, business card, official account article, music and video. Some in the group withdrew, and some individuals withdrew.

Procedure thinking

It mainly consists of two parts:

Handler_receive_msg (): processes the received message and temporarily puts it in the dictionary.

Send_msg_helper (): automatically sends the recalled message to the file transfer assistant.

Program analysis

First, we define a dictionary to store messages and define temporary paths for message storage.

Receiving information processing

First register the messages we need to process with the msg_register decorator, format the local time, and define the message ID and message time. If you are a group member and your Wechat friend withdraws the message, it shows that the name of the withdrawn message is the name of your comment, and if there is no comment name, the name is Wechat nickname.

Get messages from all your groups, determine which group the withdrawn message comes from, and show the group name.

Personal message processing

If it is a personal chat message, the comment name will be displayed first, and the nickname will be displayed if there is no comment name.

Various types of message processing

Use judgment sentences to deal with various types of messages, including text messages, Wechat's own expressions and collection of expressions, pictures, voice, location, business cards, sharing, attachments, videos. When there are many conditions, the use of in is used here. I still remember that the elegant writing of Python changed the use of or connection conditions to in, the code is more concise, so that we can constantly consolidate the knowledge points we have learned before through the project, so that we can continue to improve.

Update Information Dictionary

Processing recall messages

First determine whether to recall the message, send the recall message to your file transfer helper, and send out the sender, sending type, sending time and content of the message stored in the above function. The following is part of the code.

Principal function

Finally, the main function is used to log in and run Wechat. For the first time, you need to scan the code to log in to Wechat, and add the hotReload parameter when logging in. If it is True, the login status of the last Wechat will be saved if you run it again in a short time. There is no need to scan the code to log in again.

If _ _ name__ = ='_ _ main__':

Itchat.auto_login (hotReload=True)

Itchat.run ()

If you have a Python environment installed on your computer, run the source code directly in the editor or run the py file in cmd. The way to obtain the source code is given at the end of the paper. If necessary, it can be made into an interface tool, hang on the server, support to make an interface tool to like to see, let me see the demand, .

The above is the editor for you to share how to use Python to restore withdrawn Wechat messages, if you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

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

Internet Technology

Wechat

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

12
Report