wxpy README

The project's README from github.com/youfou/wxpy. As one markdown file: README.md.

wxpy: 用 Python 玩微信

.. image:: https://badge.fury.io/py/wxpy.svg :target: https://badge.fury.io/py/wxpy

.. image:: https://img.shields.io/pypi/pyversions/wxpy.svg :target: https://github.com/youfou/wxpy

.. image:: https://readthedocs.org/projects/wxpy/badge/?version=latest :target: http://wxpy.readthedocs.io/zh/latest/?badge=latest

微信机器人 / 可能是最优雅的微信个人号 API wxpy 在 itchat 的基础上,通过大量接口优化提升了模块的易用性,并进行丰富的功能扩展

.. attention::

| **强烈建议仅使用小号运行机器人!**

| 从近期 (17年6月下旬) 反馈来看,使用机器人存在一定概率被限制登录的可能性。
| 主要表现为无法登陆 Web 微信 (但不影响手机等其他平台)。

用来干啥

一些常见的场景

总而言之,可用来实现各种微信个人号的自动化操作

.. 体验一下 ----------------

**这有一个现成的微信机器人,想不想调戏一下?**

记得填写入群口令 👉 [ **wxpy** ],与群里的大神们谈笑风生 😏

..  image:: https://github.com/youfou/wxpy/raw/master/docs/wechat-group.png

轻松安装

wxpy 支持 Python 3.4-3.6,以及 2.7 版本

将下方命令中的 "pip" 替换为 "pip3" 或 "pip2",可确保安装到对应的 Python 版本中

  1. 从 PYPI 官方源下载安装 (在国内可能比较慢或不稳定):

.. code:: shell

pip install -U wxpy
  1. 从豆瓣 PYPI 镜像源下载安装 (推荐国内用户选用):

.. code:: shell

pip install -U wxpy -i "https://pypi.doubanio.com/simple/"

简单上手

登陆微信:

.. code:: python

# 导入模块
from wxpy import *
# 初始化机器人,扫码登陆
bot = Bot()

找到好友:

.. code:: python

# 搜索名称含有 "游否" 的男性深圳好友
my_friend = bot.friends().search('游否', sex=MALE, city="深圳")[0]

发送消息:

.. code:: python

# 发送文本给好友
my_friend.send('Hello WeChat!')
# 发送图片
my_friend.send_image('my_picture.jpg')

自动响应各类消息:

.. code:: python

# 打印来自其他好友、群聊和公众号的消息
@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('哈哈,我自动接受了你的好友请求')

保持登陆/运行:

.. code:: python

# 进入 Python 命令行、让程序保持运行
embed()

# 或者仅仅堵塞线程
# bot.join()

模块特色

说明文档

http://wxpy.readthedocs.io

更新日志

https://github.com/youfou/wxpy/releases

项目主页

https://github.com/youfou/wxpy

wxpy (youfou/wxpy)

Searching Database…

14.3K ·GitHub
archived
What is this?It's a Python library for automating a personal WeChat account: a bot API to send and receive messages and manage friends and groups from your own scripts.
So is it a ready-made bot app or something I code against?A library you code against, not a finished app: you import it, create a Bot and write handler functions. It wraps the older itchat project with a more elegant, object-oriented API and extra components.
How do I get a bot running?Run pip install -U wxpy (a Douban mirror is suggested for users in China), create a bot with Bot(), and scan the QR code it shows to log in. Call embed() to keep the script alive and explore interactively.
Will it work on my current Python?Only Python 3.4-3.6 or 2.7 — the project predates newer releases, so you'll need an older interpreter to run it.
Can I safely run this on my main WeChat account?No — WeChat restricts bots: since mid-2017 users have reported being locked out of Web WeChat login (the phone app keeps working), so the author strongly urges a throwaway account. The repo is also archived and unmaintained.
What can the bot actually do?Everyday WeChat automation: send text, images, videos and files; search friends, groups and group members by name or attributes like sex and city; read nicknames, remarks and regions; and manage contacts — add friends, create groups, invite or remove members.
How do I make it react to incoming messages?Register handler functions with @bot.register() — for all messages, a specific friend, or message types like FRIENDS to auto-accept friend requests. Replies run on multiple threads by default for fast responses, and raw itchat calls can be mixed in when needed.
What do people actually build with it?Typical uses from the README: piping script logs to your WeChat, controlling routers or smart-home devices with open APIs, forwarding messages across accounts or groups, auto-joining groups, or running a chatbot companion.
Is there anything for debugging and playing around?Yes — embed() drops you into a Python shell while the bot stays logged in, so you can poke at friends, chats and messages interactively, and a ready-made chatbot component is bundled in.
Creator
youfou
Size
0.6 MB
Stars
14.3K
Age
9y
Commits · 90 Days