前言
曾经有一份很大的红包,摆在我的面前,我没有好好珍惜,如果上天再给我一次机会,我会对发红包的人说三个字:再来个!
今天小编就教大家一个小小的Python黑科技,这样再也不用担心,抢不到红包啦~~~
1、微信红包自动提醒
2、可实现模拟点击自动抢红包
3、查看撤回消息
版本:Python3.6
系统:Windows
相关模块:itchat
查看撤回消息
红包提醒
import os
import re
import shutil
import time
import itchat
from itchat.content import *
'''
想要学习Python?Python学习交流群:683380553满足你的需求,资料都已经上传群文件流,可以自行下载!
'''
msg_dict = {}
rev_tmp_dir = "E:\文章\新建文件夹"
if not os.path.exists(rev_tmp_dir): os.mkdir(rev_tmp_dir)
face_bug = None
@itchat.msg_register([TEXT, PICTURE, MAP, CARD, SHARING, RECORDING, ATTACHMENT, VIDEO])
def handler_receive_msg(msg):
global face_bug
msg_time_rec = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
msg_id = msg['MsgId']
msg_time = msg['CreateTime']
msg_from = (itchat.search_friends(userName=msg['FromUserName']))["NickName"]
msg_content = None
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']
msg['Text'](rev_tmp_dir + msg['FileName'])
elif msg['Type'] == 'Card':
msg_content = msg['RecommendInfo']['NickName'] + r" 的名片"
elif msg['Type'] == 'Map':
x, y, location = re.search(
", msg['OriContent']).group(1, 2, 3)
if location is None:
msg_content = r"纬度->" + x.__str__() + " 经度->" + y.__str__()
else:
msg_content = r"" + location
elif msg['Type'] == 'Sharing':
msg_content = msg['Text']
msg_share_url = msg['Url']
face_bug = msg_content
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
}
}
)
@itchat.msg_register([NOTE])
def send_msg_helper(msg):
global face_bug
if re.search(r"\", msg['Content']) is not None:
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 = "告诉你一个秘密~" + "\n" \
+ old_msg.get('msg_from') + " 撤回了 " + old_msg.get("msg_type") + " 消息" + "\n" \
+ old_msg.get('msg_time_rec') + "\n" \
+ "撤回了什么 ⇣" + "\n" \
+ r"" + old_msg.get('msg_content')
if old_msg['msg_type'] == "Sharing": msg_body += "\n就是这个链接 " + old_msg.get('msg_share_url')
itchat.send(msg_body, toUserName='filehelper')
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'])
msg_dict.pop(old_msg_id)
if __name__ == '__main__':
itchat.auto_login(hotReload=True,enableCmdQR=2)
itchat.run()
自动提醒红包源码以及自动点击抢红包可查看原文链接,还有直播视频教程哟