wxpy: 用 Python 玩微信
- 微信机器人 / 可能是最优雅的微信个人号 API
wxpy 在 itchat 的基础上,通过大量接口优化提升了模块的易用性,并进行丰富的功能扩展
用来干啥
一些常见的场景
控制路由器、智能家居等具有开放接口的玩意儿
运行脚本时自动把日志发送到你的微信
加群主为好友,自动拉进群中
跨号或跨群转发消息
自动陪人聊天
逗人玩
…
总而言之,可用来实现各种微信个人号的自动化操作
体验一下
这有一个现成的微信机器人,想不想调戏一下?
记得填写入群口令 👉 [ wxpy ],与群里的大神们谈笑风生 😏
轻松安装
wxpy 支持 Python 3.4-3.6,以及 2.7 版本
将下方命令中的 “pip” 替换为 “pip3” 或 “pip2”,可确保安装到对应的 Python 版本中
从 PYPI 官方源下载安装 (在国内可能比较慢或不稳定):
pip install -U bl-wxpy
从豆瓣 PYPI 镜像源下载安装 (推荐国内用户选用):
pip install -U wxpy -i "https://pypi.doubanio.com/simple/"
简单上手
登陆微信:
# 导入模块
from wxpy import *
# 初始化机器人,扫码登陆
bot = Bot()
找到好友:
# 搜索名称含有 "游否" 的男性深圳好友
my_friend = bot.friends().search('游否', sex=MALE, city="深圳")[0]
发送消息:
# 发送文本给好友
my_friend.send('Hello WeChat!')
# 发送图片
my_friend.send_image('my_picture.jpg')
自动响应各类消息:
# 打印来自其他好友、群聊和公众号的消息
@bot.register()
def print_others(msg):
print(msg)
# 回复 my_friend 的消息 (优先匹配后注册的函数!)
@bot.register(my_friend)
def reply_my_friend(msg):
return 'received: {} ({})'.format(msg.text, msg.type)
# 自动接受新的好友请求
@bot.register(msg_types=FRIENDS)
def auto_accept_friends(msg):
# 接受好友请求
new_friend = msg.card.accept()
# 向新的好友发送消息
new_friend.send('哈哈,我自动接受了你的好友请求')
保持登陆/运行:
# 进入 Python 命令行、让程序保持运行
embed()
# 或者仅仅阻塞线程
# bot.join()
模块特色
说明文档
更新日志
项目主页
Release files for bl-wxpy 0.6.13
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bl-wxpy-0.6.13.tar.gz | 55.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bl_wxpy-0.6.13-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:128.0 kB
Release files / bl-wxpy-0.6.13.tar.gz
| Download URL | bl-wxpy-0.6.13.tar.gz |
|---|---|
| Size | 55.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
89bce0b6233347b357f8817716eeece68871ead86c8e4d4ffabba0be84d268e7
|
|
BLAKE2b-256 checksum How to use checksums |
e4bcc767a9ef41d2eafa8a80f732b19180bbfa88b3b105bb8a0c435d83af7c6a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3
|
Release files / bl_wxpy-0.6.13-py3-none-any.whl
| Download URL | bl_wxpy-0.6.13-py3-none-any.whl |
|---|---|
| Size | 72.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
be7dfb3064a62a2ca58ac4960f3cd4bf5d76d776f5aeda02e150fe419b01d356
|
|
BLAKE2b-256 checksum How to use checksums |
3e99282b7e299a31a0ab80bd98d8ac6ffc12d3856d8568fe4175290bdbdc7611
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3
|