|
4 | 4 | """
|
5 | 5 |
|
6 | 6 | wxpy
|
7 |
| -~~~~ |
8 |
| -微信个人号 API,基于 itchat,告别满屏 dict,更有 Python 范儿 |
| 7 | +======== |
9 | 8 |
|
| 9 | +微信个人号 API,基于 itchat,全面优化接口,更有 Python 范儿 |
10 | 10 |
|
11 |
| -## 代码示例 |
12 | 11 |
|
13 |
| ->>> # 导入所需的组件,也可直接 from wxpy import * |
14 |
| ->>> from wxpy import Robot, Friend, Group, MALE, TEXT |
15 |
| ->>> |
16 |
| ->>> # 初始化机器人,并登陆 |
17 |
| ->>> robot = Robot() |
18 |
| ->>> |
19 |
| ->>> # 搜索名称含有 "游否" 的男性深圳好友 |
20 |
| ->>> my_friend = robot.friends().search('游否', sex=MALE, city="深圳")[0] |
21 |
| ->>> |
22 |
| ->>> # 打印其他好友或群聊的文本消息 (装饰器语法,放在函数 def 的前一行即可) |
23 |
| ->>> @robot.register([Friend, Group], TEXT) |
24 |
| ->>> def reply_others(msg): |
25 |
| ->>> print(msg) |
26 |
| ->>> |
27 |
| ->>> # 回复 my_friend 的所有消息 (后注册的匹配优先级更高) |
28 |
| ->>> @robot.register(my_friend) |
29 |
| ->>> def reply_my_friend(msg): |
30 |
| ->>> return 'received: {} ({})'.format(msg.text, msg.type) |
31 |
| ->>> |
32 |
| ->>> # 开始监听和处理消息 |
33 |
| ->>> robot.start() |
| 12 | +用 Python 玩转微信 |
| 13 | +--------------------- |
34 | 14 |
|
| 15 | +登陆微信:: |
35 | 16 |
|
36 |
| ----- |
| 17 | + # 导入机器人组件 |
| 18 | + from wxpy import * |
| 19 | + # 初始化机器人,扫码登陆 |
| 20 | + robot = Robot() |
37 | 21 |
|
38 |
| -GitHub: https://github.com/youfou/wxpy |
| 22 | +简单发送消息:: |
39 | 23 |
|
40 |
| ----- |
| 24 | + # 给自己的 "文件传输助手" 发送消息 |
| 25 | + robot.file_helper.send('Hello WeChat!') |
| 26 | + # 发送图片 |
| 27 | + robot.file_helper.send_image('my_picture.jpg') |
41 | 28 |
|
42 |
| -:copyright: (c) 2017 by Youfou. |
43 |
| -:license: Apache 2.0, see LICENSE for more details. |
| 29 | +在微信中搜索:: |
44 | 30 |
|
45 |
| -""" |
| 31 | + # 搜索名称含有 "游否" 的男性深圳好友 |
| 32 | + my_friend = robot.friends().search('游否', sex=MALE, city="深圳")[0] |
| 33 | +
|
| 34 | +自动响应各类消息:: |
| 35 | +
|
| 36 | + # 打印来自好友或群聊的文本消息 |
| 37 | + @robot.register([Friend, Group], TEXT) |
| 38 | + def reply_others(msg): |
| 39 | + print(msg) |
46 | 40 |
|
| 41 | + # 回复 my_friend 的所有消息 (优先匹配后注册的函数!) |
| 42 | + @robot.register(my_friend) |
| 43 | + def reply_my_friend(msg): |
| 44 | + return 'received: {} ({})'.format(msg.text, msg.type) |
47 | 45 |
|
48 |
| -# 机器人 |
49 |
| -from .wx import Robot |
50 |
| -# 聊天对象类 |
51 |
| -from .wx import Chat, Chats, Friend, Group, Groups, MP, Member, User |
52 |
| -# 性别 |
53 |
| -from .wx import FEMALE, MALE |
54 |
| -# 消息类型 |
55 |
| -from .wx import ATTACHMENT, CARD, FRIENDS, MAP, NOTE, PICTURE, RECORDING, SHARING, SYSTEM, TEXT, VIDEO |
56 |
| -# 实用工具 |
57 |
| -from .utils import dont_raise_response_error, mutual_friends, ensure_one |
58 |
| -# 图灵机器人 |
59 |
| -from .utils import Tuling |
| 46 | + # 开始监听和处理消息 |
| 47 | + robot.start() |
| 48 | +
|
| 49 | +
|
| 50 | +""" |
60 | 51 |
|
| 52 | +from .utils import Tuling, dont_raise_response_error, ensure_one, mutual_friends |
| 53 | +from .wx import ATTACHMENT, CARD, FEMALE, FRIENDS, MALE, MAP, NOTE, PICTURE, RECORDING, SHARING, SYSTEM, TEXT, VIDEO |
| 54 | +from .wx import Chat, Chats, Friend, Group, Groups, MP, Member, Message, Robot, User |
61 | 55 |
|
62 | 56 | __title__ = 'wxpy'
|
63 | 57 | __version__ = '0.0.6'
|
64 | 58 | __author__ = 'Youfou'
|
65 |
| -__license__ = 'Apache 2.0' |
| 59 | +__license__ = 'MIT' |
66 | 60 | __copyright__ = 'Copyright 2017 Youfou'
|
0 commit comments