微信小脚本之python调用wxpy

14 篇文章 0 订阅
4 篇文章 0 订阅

微信小脚本之python调用wxpy

点击这里:wxpy官方文档链接


1. 安装wxpy

使用pip3安装:
pip3 install wxpy

python3中调用:
from wxpy import *


2. 模拟微信登陆和登出

Bot()跳出二维码–>扫码登陆;
当抛KeyError: 'pass_ticket'异常时,可能是因为微信安全问题:不给登陆网页版微信
bot = Bot()
bot.logout() 登出微信


3. 批量处理好友和群聊等

获取所有好友:
all_friends = bot.friends()
print(all_friends)
所有群聊(只能是已存与通讯录的): bot.groups()
所有公众号: bot.mps()


3. 向好友发送消息

给自己发消息 bot.self.send('Hello World!')
给文件传输助手发消息 bot.file_helper.send('Hello World!')

找到好友(按备注搜索)
David = bot.friends().search('David')[0]

向该好友发送信息/图片
David.send('Hello!')
David.send_image('test.jpg')


4. 自动处理消息

注意: embed()函数加在某位,可以让脚本始终保持运行,除非报错

msg含有两个属性

  • text: 消息内容
  • type: 消息格式

脚本1:对所有消息一律回复(包括推送)

@bot.register()
def print_others(msg):
	# 这里的msg是:文字则text格式,图片则picture格式
	print(msg) # 打印对方发来的消息
	msg.reply('您好我有事不在') # 自动回复

脚本2:回复指定好友消息

# David是friends().search()返回的对象
@bot.register(David)
def print_others(msg):
	......
	# 此时只回复Daivd发来的消息

脚本3:自动接收好友请求

@bot.register(msg_types=FRIENDS)
def auto_accept_friends(msg):
    # 接受好友请求
    new_friend = msg.card.accept()
    # 向新的好友发送消息
    new_friend.send('哈哈,我自动接受了你的好友请求')

脚本4:一个自动计算器

3*(5-2)
自动回复:9

@bot.register()
def print_others(msg):
	if msg.type == 'Text':
		msg.reply(str(eval(str(msg.text)))
embed()

脚本5:手写识别+计算器=小猿搜题简化版

待完成。。。
使用tesseract库
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值