In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to prevent Wechat withdrawal in Python? 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.
In the process of using Wechat, sometimes the message is withdrawn before it can be seen. After all, everyone has curiosity, knowing that the news has been withdrawn, they would like to see what it is.
I thought to myself that if the goddess confessed her love to me...
Train of thought:
Use the itchat library to cache each received message. Listen for recall events, and when a disappearance is withdrawn, the information is fetched from the cache by msgId and sent to the file transfer assistant. In this way, a simple anti-withdrawal function is implemented.
Effect picture
Python Learning tutorial Operation: cache received messages
Import itchat
From itchat.content import *
Import datetime
Import re
Import os
# Storage path of information accepted by Wechat
FILE_PATH ='/ home/wechat/'
# cached Dictionary for Wechat messages
MSG_DICT = {}
# Wechat message Type Dictionary
MSG_MESSAGE = {'Text':' text', 'Map':' location sharing', 'Sharing':' sharing link'
'Picture':' pictures, 'Video':' videos, 'Card':' business cards'
'Attachment':' attachment', 'Recording':' voice'}
"
Listen for messages
"
# listening messages are TEXT, MAP, SHARING, PICTURE, VIDEO, CARD, RECORDING, ATTACHMENT
Itchat.msg_register ([TEXT, MAP, SHARING, PICTURE, VIDEO, CARD, RECORDING, ATTACHMENT])
Def wechat_msg (msg):
# get message id
Msg_id = msg ['MsgId']
# current time
Msg_time = datetime.datetime.now () .strftime ('% Y-%m-%d% HRV% MRV% S')
# sender
Msg_from = itchat.search_friends (userName=msg ['FromUserName']) [' RemarkName']
# Note: empty to get nickname
If not msg_from:
Msg_from = itchat.search_friends (userName=msg ['FromUserName']) [' NickName']
# content
Msg_text = msg ['Text']
# message type
Msg_type = msg ['Type']
Msg_url = None
# you need to save messages when they are videos, photos, voice messages or attachments
Save_type = [VIDEO, PICTURE, RECORDING, ATTACHMENT]
If msg_type in save_type:
# Save the file
Msg ['Text'] (FILE_PATH + msg [' FileName'])
Msg_text = msg ['FileName']
# message type is map, record url when sharing links
Url_type = [MAP, SHARING]
If msg_type in url_type:
Msg_url = msg ['msg_url']
# Business card
If msg_type = = CARD:
Sex = msg ['RecommendInfo'] [' Sex']
If sex = = 1:
Sex = 'elder brother'
Elif sex = = 2:
Sex = 'Sister'
Else:
Sex = 'ladyBoy'
Msg_text = f 'business card from {msg ["RecommendInfo"] ["Province"]} {msg ["RecommendInfo"] ["City"]} {msg ["RecommendInfo"] ["NickName"]} {sex}.
# messages are put in the dictionary
MSG_ DICT [msg _ id] = {'msg_from': msg_from,' msg_time': msg_time, 'msg_text': msg_text,' msg_url': msg_url, 'msg_type': MSG_ Mesage [msg _ type]}
Print ({'msg_from': msg_from,' msg_time': msg_time, 'msg_text': msg_text,' msg_url': msg_url, 'msg_type': MSG_ MESSAGE [MSG _ type]})
We cache the text, video, voice, image, attachment and other message types received by Wechat into the MSG_DICT dictionary. Next, we can monitor the withdrawal incident.
This is the end of the answer to the question on how to prevent Wechat withdrawal in Python. 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.