In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to use Python code to view recalled Wechat messages, for this question, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
Introduction: Python once said to me: "time is running out, hurry up and use Python." So I saw an open source library for Wechat based on python: itchat. After playing for a day, I made a program that can collect and send information about private chat withdrawal to personal Wechat's file transfer assistant, including:
(1) who: who sent it
(2) when: when was the message sent?
(3) what: what information
(4) which: what kind of information, including text, picture, voice, video, sharing, location, attachment
...
01 code implementation
#-*-encoding:utf-8-*- import os import re import shutil import time import itchat from itchat.content import * # Note: text, voice, video, picture, location, business card, sharing, attachment # {msg_id: (msg_from,msg_to,msg_time,msg_time_rec,msg_type,msg_content) can be withdrawn. Msg_share_url)} msg_dict = {} # temporary directory for file storage rev_tmp_dir = "/ home/alic/RevDir/" if not os.path.exists (rev_tmp_dir): os.mkdir (rev_tmp_dir) # emoji has a problem | msg_id inconsistency between accepting messages and accepting note solution face_bug = None # stores received messages in a dictionary Clean up timeout messages in the dictionary when receiving new messages | do not accept messages without recall # [TEXT, PICTURE, MAP, CARD, SHARING, RECORDING, ATTACHMENT, VIDEO, FRIENDS, NOTE] @ itchat.msg_register ([TEXT, PICTURE, MAP, CARD, SHARING, RECORDING, ATTACHMENT) VIDEO]) def handler_receive_msg (msg): global face_bug # takes the local timestamp and formats the local timestamp e: 2017-04-21 21:30:08 msg_time_rec = time.strftime ("% Y-%m-%d% H:%M:%S" Time.localtime () # message ID msg_id = msg ['MsgId'] # message time msg_time = msg [' CreateTime'] # nickname of the sender | you can also use RemarkName comments here, but you or those who do not have comments None msg_from = (itchat.search_friends (userName=msg ['FromUserName'])) ["NickName"] # within the message. Allow msg_content = None # shared links msg_share_url = None if msg ['Type'] = =' Text'\ or msg ['Type'] = =' Friends': msg_content = msg ['Text'] elif msg [' Type'] = 'Recording'\ or msg [' Type'] = = 'Attachment'\ Or msg ['Type'] =' Video'\ or msg ['Type'] =' Picture': msg_content = r "" + msg ['FileName'] # Save the file msg [' Text'] (rev_tmp_dir + msg ['FileName']) elif msg [' Type'] = 'Card': msg_content = msg [' RecommendInfo'] [' NickName'] + r "business card" elif msg ['Type'] = =' Map': x Y Location = re.search ("+ x.longitude stratum _ () +" longitude-> "+ y.longitude stratum _ () else: msg_content = r" + location elif msg ['Type'] = =' Sharing': msg_content = msg ['Text'] msg_share_url = msg [' Url'] face_bug = msg_ Content # update dictionary msg_dict.update ({msg_id: {"msg_from": msg_from "msg_time": msg_time, "msg_time_rec": msg_time_rec, "msg_type": msg ["Type"], "msg_content": msg_content, "msg_share_url": msg_share_url}}) # received note notification message Determine whether to withdraw and perform the corresponding operation @ itchat.msg_register ([NOTE]) def send_msg_helper (msg): global face_bug if re.search (r "\", msg ['Content']) is not None: # get the message id old_msg_id = re.search ("\ (. *?)\" Msg ['Content']) .group (1) old_msg = msg_dict.get (old_msg_id, {}) if len (old_msg_id) < 11: itchat.send_file (rev_tmp_dir + face_bug) ToUserName='filehelper') os.remove (rev_tmp_dir + face_bug) else: msg_body = "tell you a secret ~" + "\ n"\ + old_msg.get ('msg_from') + "withdraw" + old_msg.get ("msg_type") + "message" + "\ n"\ + old_msg.get ('msg_time_rec') + "\ n"\ + "withdrew what ⇣" + "\ n"\ + r "" + old_msg.get (' msg_content') # if it is a shared existence link if old_ Msg ['msg_type'] = = "Sharing": msg_body + = "\ n this is the link ➣" + old_msg.get (' msg_share_url') # sends the recall message to the file assistant itchat.send (msg_body) ToUserName='filehelper') # send the file back to if old_msg ["msg_type"] = = "Picture"\ or old_msg ["msg_type"] = = "Recording"\ or old_msg ["msg_type"] = = "Video"\ or Old_msg ["msg_type"] = = "Attachment": file ='@ fil@%s'% (rev_tmp_dir + old_msg ['msg_content']) itchat.send (msg=file) ToUserName='filehelper') os.remove (rev_tmp_dir + old_msg ['msg_content']) # delete dictionary old message msg_dict.pop (old_msg_id) if _ _ name__ =' _ _ main__': itchat.auto_login (hotReload=True,enableCmdQR=2) itchat.run ()
The program can be run directly in the terminal, and can be successfully logged in after scanning the code at the terminal. At the same time, it can also be packaged and run in the window system (note that the path is modified and the relative path is recommended).
➜~ python wx.py Getting uuid of QR code. Downloading QR code. Please scan the QR code to log in. Please press confirm on your phone. Loading the contact, this may take a little while. [3th J Login successfully as AlicFeng Start auto replying.
02 effect picture
03 itchat
The above are all the little things of programming logic, so I'll record the open source library itchat Wechat.
1. Brief introduction
Itchat is an open source Wechat personal ID interface, which makes it very easy to use python to call Wechat. You can simply use itchat code to build an instant messaging based on Wechat. A better reflection is that it is convenient to expand more communication functions of personal Wechat in other platforms.
two。 Installation
Pip3 install itchat
3. Itchat-Helloworld
Just three lines of code sends a message to the file transfer assistant.
Import itchat itchat.auto_login (hotReload=True) itchat.send ('Hello AlicFeng', toUserName='filehelper')
4. View client
This is the end of the answer to the question on how to view the withdrawn Wechat message with Python code. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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.