微信防撤回python_python使用wxpy实现微信消息防撤回脚本
本文实例为大家分享了python实现微信消息防撤回的具体代码,供大家参考,具体内容如下
使用了sqlite3保存数据,当有人撤回消息时取出数据发送到文件传输助手。
文件的话会先保存到本地,语音会以文件的方式发送。
wxpy 和 itchat很久没更新了,有些功能没法用了,web微信也不知道什么时候会凉。
帮助信息在注释里。
# -*- coding: utf-8 -*-
# 使用sqlite3保存message,当有人撤回消息时在数据库中通过id检索该消息是否存在,如果存在则将撤回的消息发送到文件助手里。
# 目前只支持 text picture map sharing recording video attachment 类型的消息。
import wxpy
import sqlite3
import os
import re
# 准备工作
# 创建attachment目录用于存储 图像、地图/位置、分享、语音、视频、文件
if not os.path.isdir('attachment'):
os.mkdir('attachment')
attachment_path = os.path.join(os.getcwd(), 'attachment')
bot = wxpy.bot()
# 用于获取msg id
pattern = re.compile(r'\d{19}')
# 测试wxpy能否正常工作
myself = bot.friends()[0]
myself.send('hello?')
# 创建数据库和message表
try:
conn = sqlite3.connect('wxpy.db')
cursor = conn.cursor()
# cursor.execute('drop table messages')
cursor.execute("""create table if not exists messages (id integer primary key autoincrement,
msg_id integer not null,
msg_text text,
create_time date not null,
revoke_time date,
attachment_path text,
msg_sender text not null,
msg_type text not null,
msg_url text,
msg_raw_data text not null)""")
# print('establish successfully')
finally:
conn.commit()
cursor.close()
conn.close()
# 注册所有消息,在程序运行期间将插入所有支持的信息
@bot.register()
def store_data(msg):
# print(msg.raw)
# 如果消息是支持的类型就将数据插入数据库
if msg.type in [wxpy.text, wxpy.recording, wxpy.picture, wxpy.attachment, wxpy.video, wxpy.sharing, wxpy.map]:
insert_data(msg)
# 撤回的消息类型是note
elif msg.type == wxpy.note:
send_revoke(msg)
# 插入数据
def insert_data(msg):
try:
conn = sqlite3.connect('wxpy.db')
cursor = conn.cursor()
if msg.type == wxpy.text:
cursor.execute("insert into messages (msg_id, msg_text, create_time, msg_sender, msg_type, msg_raw_data)\
values (?, ?, ?, ?, ?, ?)", (msg.id, msg.text, msg.create_time, str(msg.sender)[9:-1],
msg.type, str(msg.raw)))
# 将录音/图像/文件/视频下载到本地,插入保存路径。
elif msg.type in [wxpy.recording, wxpy.picture, wxpy.attachment, wxpy.video]:
save_path = os.path.join(attachment_path, msg.file_name)
msg.get_file(save_path)
cursor.execute('insert into messages (msg_id, create_time, attachment_path, msg_sender, msg_type,\
msg_raw_data) values (?, ?, ?, ?, ?, ?)',
(msg.id, msg.create_time, save_path, str(msg.sender)[9:-1], msg.type, str(msg.raw)))
# 插入分享/位置链接
elif msg.type in [wxpy.sharing, wxpy.map]:
cursor.execute('insert into messages (msg_id, msg_text, create_time, msg_sender, msg_type, msg_url,\
msg_raw_data) values (?, ?, ?, ?, ?, ?, ?)',
(msg.id, msg.text, msg.create_time, str(msg.sender)[9:-1], msg.type, str(msg.url), str(msg.raw)))
# print('insert data successfully')
finally:
conn.commit()
cursor.close()
conn.close()
# 在数据库中检索消息是否存在,如果存在则将被撤回的消息发送到文件传输助手。
def send_revoke(message):
msg_id = pattern.search(message.raw['content']).group()
try:
conn = sqlite3.connect('wxpy.db')
cursor = conn.cursor()
cursor.execute('insert into messages (msg_id, create_time, msg_sender, msg_type, msg_raw_data)\
values (?, ?, ?, ?, ?)',
(message.id, message.create_time, str(message.sender)[9:-1], message.type, str(message.raw)))
msg_data = cursor.execute('select * from messages where msg_id=?', (msg_id, )).fetchall()
# print('take out data successfully')
finally:
conn.commit()
cursor.close()
conn.close()
if msg_data[0][7] == 'text':
msg_info = '告诉你一个秘密 {} 在 {} 撤回了文本\n{}'.format(msg_data[0][6], msg_data[0][3], msg_data[0][2])
bot.file_helper.send(msg_info)
else:
send_revoke_nontext(msg_data)
# 非文本信息发送
def send_revoke_nontext(msg_data):
if msg_data[0][7] == 'picture':
if msg_data[0][5][-4:] == '.gif':
# 现在wxpy & itchat发不了gif了
bot.file_helper('很抱歉,暂时不支持表情(gif)的撤回重发。')
else:
msg_info = '告诉你一个秘密 {} 在 {} 撤回了图像'.format(msg_data[0][6], msg_data[0][3])
bot.file_helper.send(msg_info)
bot.file_helper.send_image(msg_data[0][5])
elif msg_data[0][7] == 'recording':
msg_info = '告诉你一个秘密 {} 在 {} 撤回了语音'.format(msg_data[0][6], msg_data[0][3])
bot.file_helper.send(msg_info)
bot.file_helper.send_file(msg_data[0][5])
elif msg_data[0][7] == 'attachment':
msg_info = '告诉你一个秘密 {} 在 {} 撤回了文件'.format(msg_data[0][6], msg_data[0][3])
bot.file_helper.send(msg_info)
bot.file_helper.send_file(msg_data[0][5])
elif msg_data[0][7] == 'video':
msg_info = '告诉你一个秘密 {} 在 {} 撤回了视频'.format(msg_data[0][6], msg_data[0][3])
bot.file_helper.send(msg_info)
bot.file_helper.send_video(msg_data[0][5])
elif msg_data[0][7] == 'sharing':
msg_info = '告诉你一个秘密 {} 在 {} 撤回了分享\n{}\n{}'.format(msg_data[0][6], msg_data[0][3], msg_data[0][2],\
msg_data[0][8])
bot.file_helper.send(msg_info)
elif msg_data[0][7] == 'map':
msg_info = '告诉你一个秘密 {} 在 {} 撤回了位置\n{}\n{}'.format(msg_data[0][6], msg_data[0][3], msg_data[0][2],\
msg_data[0][8])
bot.file_helper.send(msg_info)
wxpy.embed()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持萬仟网。
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!
微信防撤回python_python使用wxpy实现微信消息防撤回脚本相关推荐
- 微信多开软件苹果版_微信最新PC版 无限多开以及消息防撤回
今日头条:教你电脑如何微信多开 现在很多人都是工作一个号,生活一个号.现在越来越多的手机已经支持微信多开,但是很多小伙伴问我什么时候电脑也能支持微信多开呢?现在的电脑只能挂一个微信真的好麻烦啊! 微 ...
- 微信多开软件苹果版_微信PC版、无限多开、消息防撤回补丁
这个软件就厉害啦,不仅可以多开微信,还可以看到别人撤回的内容.万一看到什么可以吃瓜的信息岂不美哉??哈哈! 软件功能如下:1.Windows7及以上系统新增小程序面板,可查看最近使用和我的小程序2.聊 ...
- Python实现微信消息防撤回
微信(WeChat)是腾讯公司于2011年1月21日推出的一款社交软件,8年时间微信做到日活10亿,日消息量450亿.在此期间微信也推出了不少的功能如:"摇一摇"."漂流 ...
- 微信防撤回python代码_Python实现微信防撤回
微信(WeChat)是腾讯公司于2011年1月21日推出的一款社交软件,8年时间微信做到日活10亿,日消息量450亿.在此期间微信也推出了不少的功能如:"摇一摇"."漂流 ...
- #Python #微信 #消息防撤回 Python实现微信防撤回
微信(WeChat)是腾讯公司于2011年1月21日推出的一款社交软件,8年时间微信做到日活10亿,日消息量450亿.在此期间微信也推出了不少的功能如:"摇一摇"."漂流 ...
- 微信防撤回python代码_python实现微信消息防撤回
微信(WeChat)是腾讯公司于2011年1月21日推出的一款社交软件,8年时间微信做到日活10亿,日消息量450亿.在此期间微信也推出了不少的功能如:"摇一摇"."漂 ...
- 用python实现语音的传输功能_用Python+WechatPCAPI实现微信消息防撤回
干货分享 干货 | Python学习资源整理分享mp.weixin.qq.com 引言 最近逛GitHub时发现了一个半开源的微信PC版的API接口WechatPCAPI,研究了一下,发现还是很好用 ...
- 如何使用 Python 实现微信消息防撤回
在微信上突然看到"XXX撤回一条消息"的时候,心里痒不痒?现在就教你如何实现消息防撤回的功能.不限手机型号.手机无需root,只要微信号可以登上网页版就可以了(部分不常用和新申请的 ...
- 微信防撤回python代码_python实现微信防撤回神器
本文实例为大家分享了python实现微信防撤回神器的具体代码,供大家参考,具体内容如下 手写辛苦,希望给赞 #!/usr/local/bin/python3 # coding=utf-8 import ...
最新文章
- 拥抱 Java 8 并行流吧,让执行速度飞起!
- fiddler使用_fiddler基础使用
- c语言malloc函数用法_小白对c语言数组的基础总结
- elasticsearch导入数据的几种方法
- CTFshow 命令执行 web46
- 【揭秘】网易云视频点播加解密系统架构
- 【渝粤题库】陕西师范大学164202 市场营销学 作业(专升本)
- 二维分类教案_幼儿园中班数学教案中班数学教案二维排序——师乐汇幼儿教师教育网...
- 【2016年第6期】专题:科学数据与创新应用
- 《Java 7 并发编程指南》学习概要 (3)Semaphore, CountDownLatch, CyclicBarrier , Phaser, Exchanger...
- 学习Python编程培训 有哪些爬虫技术课程需要掌握
- 高中计算机学考题库,高中信息技术学业水平考试试题汇总(含答案)
- Android实现百度离线地图+gps定位
- JavaSE项目——嗖嗖移动大厅(详细注释,java基础知识基本上都包含了)
- el-menu菜单下划线解决办法
- 出现ora-01400错误解决办法
- (弃更)一些黑科技和技巧
- UE4之材质球UV缩放、偏移及旋转
- 什么是java框架结构_什么是JAVA类集框架啊?具体指的是什么?是JAVA类的框架结构么?...
- 面渣逆袭:Spring三十五问,四万字+五十图详解,建议收藏。
热门文章
- javascript 防止息屏
- python 删除 csv 文件的行
- 十六、希尔排序即其优化(交换法--->移动法)
- Linux下的vim文本替换,Linux下文本的vim文本替换
- cs go linux 参数,CSGO 命令大全 给新手的福利 使用设置参数
- php无法引用,PHP错误:“无法通过引用传递参数2”
- 基于K8S构建企业级Jenkins CI/CD平台实战(二) 之 kubernetes-plugin 插件使用
- 本地Windows 7/8上搭建IIS服务器
- centos8.2 hyper第一代 第二代_欧洲第一代法王以工程师身份加入拳头游戏,网友齐呼:是真的牛...
- 阿里软件测试工程师手把手教学——如何更好地设计测试用例?