├── .github
├── ISSUE_TEMPLATE.md
└── PULL_REQUEST_TEMPLATE.md
├── .gitignore
├── LICENSE
├── README.md
├── README.rst
├── README_EN.md
├── docs
├── FAQ.md
├── api.md
├── bootstrap
│ ├── __init__.py
│ ├── base.html
│ ├── content.html
│ ├── css
│ │ ├── base.css
│ │ ├── bootstrap-3.0.3.min.css
│ │ ├── font-awesome-4.0.3.css
│ │ └── highlight.css
│ ├── fonts
│ │ ├── fontawesome-webfont.eot
│ │ ├── fontawesome-webfont.svg
│ │ ├── fontawesome-webfont.ttf
│ │ └── fontawesome-webfont.woff
│ ├── img
│ │ └── favicon.ico
│ ├── js
│ │ ├── base.js
│ │ ├── bootstrap-3.0.3.min.js
│ │ ├── highlight.pack.js
│ │ └── jquery-1.10.2.min.js
│ ├── main.html
│ ├── nav.html
│ └── toc.html
├── index.md
├── intro
│ ├── contact.md
│ ├── deploy.md
│ ├── handler.md
│ ├── login.md
│ ├── messages.md
│ ├── reply.md
│ └── start.md
├── requirements.txt
└── tutorial
│ ├── tutorial0.md
│ ├── tutorial1.md
│ └── tutorial2.md
├── itchat
├── __init__.py
├── components
│ ├── __init__.py
│ ├── contact.py
│ ├── hotreload.py
│ ├── login.py
│ ├── messages.py
│ └── register.py
├── config.py
├── content.py
├── core.py
├── log.py
├── returnvalues.py
├── storage
│ ├── __init__.py
│ ├── messagequeue.py
│ └── templates.py
└── utils.py
├── mkdocs.yml
└── setup.py
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | 在提交前,请确保您已经检查了以下内容!
2 |
3 | - [ ] 您可以在浏览器中登陆微信账号,但不能使用`itchat`登陆
4 | - [ ] 我已经阅读并按[文档][document] 中的指引进行了操作
5 | - [ ] 您的问题没有在[issues][issues]报告,否则请在原有issue下报告
6 | - [ ] 本问题确实关于`itchat`, 而不是其他项目.
7 | - [ ] 如果你的问题关于稳定性,建议尝试对网络稳定性要求极低的[itchatmp][itchatmp]项目
8 |
9 | 请使用`itchat.run(debug=True)`运行,并将输出粘贴在下面:
10 |
11 | ```
12 | [在这里粘贴完整日志]
13 | ```
14 |
15 | 您的itchat版本为:`[在这里填写版本号]`。(可通过`python -c "import itchat;print(itchat.__version__)"`获取)
16 |
17 | 其他的内容或者问题更详细的描述都可以添加在下面:
18 |
19 | > [您的内容]
20 |
21 | [document]: http://itchat.readthedocs.io/zh/latest/
22 | [issues]: https://github.com/littlecodersh/itchat/issues
23 | [itchatmp]: https://github.com/littlecodersh/itchatmp
24 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | **(阅读后请删除所有内容)**
2 |
3 | 感谢您的pull request! `itchat`没有你们的帮助很难发展到今天,感谢您的贡献.
4 |
5 | 以下简单检查项目望您复查:
6 |
7 | - [ ] 如果您预计提出两个或更多不相关补丁,请为每个使用不同的pull requests,而不是单一;
8 | - [ ] 所有的pull requests应基于最新的`master`分支;
9 | - [ ] 您预计提出pull requests的分支应有有意义名称,例如`add-this-shining-feature`而不是`develop`;
10 | - [ ] 所有的提交信息与代码中注释应使用可理解的英语.
11 |
12 | 作为贡献者,您需要知悉
13 |
14 | - [ ] 您同意在MIT协议下贡献代码,以便任何人自由使用或分发;当然,你仍旧保留代码的著作权
15 | - [ ] 你不得贡献非自己编写的代码,除非其属于公有领域或使用MIT协议.
16 |
17 | 不是所有的pull requests都会被合并,然而我认为合并/不合并的补丁一样重要。
18 | 如果您认为补丁重要,其他人也有可能这么认为,那么他们可以从你的fork中提取工作并获益。
19 | 无论如何,感谢您费心对本项目贡献.
20 |
21 | 祝好,
22 |
23 | LittleCoder, 170308
24 |
25 | **(请将本内容完整替换为PULL REQUEST的详细内容)**
26 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | build/*
2 | dist/*
3 | tests/*
4 | itchat.egg-info/*
5 | *.pyc
6 | *.pkl
7 | *.swp
8 | test.py
9 | itchat.pkl
10 | QR.jpg
11 | .DS_Store
12 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | **The MIT License (MIT)**
2 |
3 | Copyright (c) 2017 LittleCoder ([littlecodersh@Github](https://github.com/littlecodersh))
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # itchat
2 |
3 | [![Gitter][gitter-picture]][gitter] ![py27][py27] ![py35][py35] [English version][english-version]
4 |
5 | itchat是一个开源的微信个人号接口,使用python调用微信从未如此简单。
6 |
7 | 使用不到三十行的代码,你就可以完成一个能够处理所有信息的微信机器人。
8 |
9 | 当然,该api的使用远不止一个机器人,更多的功能等着你来发现,比如[这些][tutorial2]。
10 |
11 | 该接口与公众号接口[itchatmp][itchatmp]共享类似的操作方式,学习一次掌握两个工具。
12 |
13 | 如今微信已经成为了个人社交的很大一部分,希望这个项目能够帮助你扩展你的个人的微信号、方便自己的生活。
14 |
15 | ## 安装
16 |
17 | 可以通过本命令安装itchat:
18 |
19 | ```python
20 | pip install itchat
21 | ```
22 |
23 | ## 简单入门实例
24 |
25 | 有了itchat,如果你想要给文件传输助手发一条信息,只需要这样:
26 |
27 | ```python
28 | import itchat
29 |
30 | itchat.auto_login()
31 |
32 | itchat.send('Hello, filehelper', toUserName='filehelper')
33 | ```
34 |
35 | 如果你想要回复发给自己的文本消息,只需要这样:
36 |
37 | ```python
38 | import itchat
39 |
40 | @itchat.msg_register(itchat.content.TEXT)
41 | def text_reply(msg):
42 | return msg.text
43 |
44 | itchat.auto_login()
45 | itchat.run()
46 | ```
47 |
48 | 一些进阶应用可以在下面的开源机器人的源码和进阶应用中看到,或者你也可以阅览[文档][document]。
49 |
50 | ## 试一试
51 |
52 | 这是一个基于这一项目的[开源小机器人][robot-source-code],百闻不如一见,有兴趣可以尝试一下。
53 |
54 | 由于好友数量实在增长过快,自动通过好友验证的功能演示暂时关闭。
55 |
56 | ![QRCode][robot-qr]
57 |
58 | ## 截屏
59 |
60 | ![file-autoreply][robot-demo-file] ![login-page][robot-demo-login]
61 |
62 | ## 进阶应用
63 |
64 | ### 特殊的字典使用方式
65 |
66 | 通过打印itchat的用户以及注册消息的参数,可以发现这些值都是字典。
67 |
68 | 但实际上itchat精心构造了相应的消息、用户、群聊、公众号类。
69 |
70 | 其所有的键值都可以通过这一方式访问:
71 |
72 | ```python
73 | @itchat.msg_register(TEXT)
74 | def _(msg):
75 | # equals to print(msg['FromUserName'])
76 | print(msg.fromUserName)
77 | ```
78 |
79 | 属性名为键值首字母小写后的内容。
80 |
81 | ```python
82 | author = itchat.search_friends(nickName='LittleCoder')[0]
83 | author.send('greeting, littlecoder!')
84 | ```
85 |
86 | ### 各类型消息的注册
87 |
88 | 通过如下代码,微信已经可以就日常的各种信息进行获取与回复。
89 |
90 | ```python
91 | import itchat, time
92 | from itchat.content import *
93 |
94 | @itchat.msg_register([TEXT, MAP, CARD, NOTE, SHARING])
95 | def text_reply(msg):
96 | msg.user.send('%s: %s' % (msg.type, msg.text))
97 |
98 | @itchat.msg_register([PICTURE, RECORDING, ATTACHMENT, VIDEO])
99 | def download_files(msg):
100 | msg.download(msg.fileName)
101 | typeSymbol = {
102 | PICTURE: 'img',
103 | VIDEO: 'vid', }.get(msg.type, 'fil')
104 | return '@%s@%s' % (typeSymbol, msg.fileName)
105 |
106 | @itchat.msg_register(FRIENDS)
107 | def add_friend(msg):
108 | msg.user.verify()
109 | msg.user.send('Nice to meet you!')
110 |
111 | @itchat.msg_register(TEXT, isGroupChat=True)
112 | def text_reply(msg):
113 | if msg.isAt:
114 | msg.user.send(u'@%s\u2005I received: %s' % (
115 | msg.actualNickName, msg.text))
116 |
117 | itchat.auto_login(True)
118 | itchat.run(True)
119 | ```
120 |
121 | ### 命令行二维码
122 |
123 | 通过以下命令可以在登陆的时候使用命令行显示二维码:
124 |
125 | ```python
126 | itchat.auto_login(enableCmdQR=True)
127 | ```
128 |
129 | 部分系统可能字幅宽度有出入,可以通过将enableCmdQR赋值为特定的倍数进行调整:
130 |
131 | ```python
132 | # 如部分的linux系统,块字符的宽度为一个字符(正常应为两字符),故赋值为2
133 | itchat.auto_login(enableCmdQR=2)
134 | ```
135 |
136 | 默认控制台背景色为暗色(黑色),若背景色为浅色(白色),可以将enableCmdQR赋值为负值:
137 |
138 | ```python
139 | itchat.auto_login(enableCmdQR=-1)
140 | ```
141 |
142 | ### 退出程序后暂存登陆状态
143 |
144 | 通过如下命令登陆,即使程序关闭,一定时间内重新开启也可以不用重新扫码。
145 |
146 | ```python
147 | itchat.auto_login(hotReload=True)
148 | ```
149 |
150 | ### 用户搜索
151 |
152 | 使用`search_friends`方法可以搜索用户,有四种搜索方式:
153 | 1. 仅获取自己的用户信息
154 | 2. 获取特定`UserName`的用户信息
155 | 3. 获取备注、微信号、昵称中的任何一项等于`name`键值的用户
156 | 4. 获取备注、微信号、昵称分别等于相应键值的用户
157 |
158 | 其中三、四项可以一同使用,下面是示例程序:
159 |
160 | ```python
161 | # 获取自己的用户信息,返回自己的属性字典
162 | itchat.search_friends()
163 | # 获取特定UserName的用户信息
164 | itchat.search_friends(userName='@abcdefg1234567')
165 | # 获取任何一项等于name键值的用户
166 | itchat.search_friends(name='littlecodersh')
167 | # 获取分别对应相应键值的用户
168 | itchat.search_friends(wechatAccount='littlecodersh')
169 | # 三、四项功能可以一同使用
170 | itchat.search_friends(name='LittleCoder机器人', wechatAccount='littlecodersh')
171 | ```
172 |
173 | 关于公众号、群聊的获取与搜索在文档中有更加详细的介绍。
174 |
175 | ### 附件的下载与发送
176 |
177 | itchat的附件下载方法存储在msg的Text键中。
178 |
179 | 发送的文件的文件名(图片给出的默认文件名)都存储在msg的FileName键中。
180 |
181 | 下载方法接受一个可用的位置参数(包括文件名),并将文件相应的存储。
182 |
183 | ```python
184 | @itchat.msg_register([PICTURE, RECORDING, ATTACHMENT, VIDEO])
185 | def download_files(msg):
186 | msg.download(msg.fileName)
187 | itchat.send('@%s@%s' % (
188 | 'img' if msg['Type'] == 'Picture' else 'fil', msg['FileName']),
189 | msg['FromUserName'])
190 | return '%s received' % msg['Type']
191 | ```
192 |
193 | 如果你不需要下载到本地,仅想要读取二进制串进行进一步处理可以不传入参数,方法将会返回图片的二进制串。
194 |
195 | ```python
196 | @itchat.msg_register([PICTURE, RECORDING, ATTACHMENT, VIDEO])
197 | def download_files(msg):
198 | with open(msg.fileName, 'wb') as f:
199 | f.write(msg.download())
200 | ```
201 |
202 | ### 用户多开
203 |
204 | 使用如下命令可以完成多开的操作:
205 |
206 | ```python
207 | import itchat
208 |
209 | newInstance = itchat.new_instance()
210 | newInstance.auto_login(hotReload=True, statusStorageDir='newInstance.pkl')
211 |
212 | @newInstance.msg_register(itchat.content.TEXT)
213 | def reply(msg):
214 | return msg.text
215 |
216 | newInstance.run()
217 | ```
218 |
219 | ### 退出及登陆完成后调用特定方法
220 |
221 | 登陆完成后的方法需要赋值在`loginCallback`中。
222 |
223 | 而退出后的方法需要赋值在`exitCallback`中。
224 |
225 | ```python
226 | import time
227 |
228 | import itchat
229 |
230 | def lc():
231 | print('finish login')
232 | def ec():
233 | print('exit')
234 |
235 | itchat.auto_login(loginCallback=lc, exitCallback=ec)
236 | time.sleep(3)
237 | itchat.logout()
238 | ```
239 |
240 | 若不设置loginCallback的值,则将会自动删除二维码图片并清空命令行显示。
241 |
242 | ## 常见问题与解答
243 |
244 | Q: 如何通过这个包将自己的微信号变为控制器?
245 |
246 | A: 有两种方式:发送、接受自己UserName的消息;发送接收文件传输助手(filehelper)的消息
247 |
248 | Q: 为什么我发送信息的时候部分信息没有成功发出来?
249 |
250 | A: 有些账号是天生无法给自己的账号发送信息的,建议使用`filehelper`代替。
251 |
252 | ## 作者
253 |
254 | [LittleCoder][littlecodersh]: 构架及维护Python2 Python3版本。
255 |
256 | [tempdban][tempdban]: 协议、构架及日常维护。
257 |
258 | [Chyroc][Chyroc]: 完成第一版本的Python3构架。
259 |
260 | ## 类似项目
261 |
262 | [youfou/wxpy][youfou-wxpy]: 优秀的api包装和配套插件,微信机器人/优雅的微信个人号API
263 |
264 | [liuwons/wxBot][liuwons-wxBot]: 类似的基于Python的微信机器人
265 |
266 | [zixia/wechaty][zixia-wechaty]: 基于Javascript(ES6)的微信个人账号机器人NodeJS框架/库
267 |
268 | [sjdy521/Mojo-Weixin][Mojo-Weixin]: 使用Perl语言编写的微信客户端框架,可通过插件提供基于HTTP协议的api接口供其他语言调用
269 |
270 | [HanSon/vbot][HanSon-vbot]: 基于PHP7的微信个人号机器人,通过实现匿名函数可以方便地实现各种自定义的功能
271 |
272 | [yaphone/itchat4j][yaphone-itchat4j]: 用Java扩展个人微信号的能力
273 |
274 | [kanjielu/jeeves][kanjielu-jeeves]: 使用springboot开发的微信机器人
275 |
276 | ## 问题和建议
277 |
278 | 如果有什么问题或者建议都可以在这个[Issue][issue#1]和我讨论
279 |
280 | 或者也可以在gitter上交流:[![Gitter][gitter-picture]][gitter]
281 |
282 | 当然也可以加入我们新建的QQ群讨论:549762872, 205872856
283 |
284 | [gitter-picture]: https://badges.gitter.im/littlecodersh/ItChat.svg
285 | [gitter]: https://gitter.im/littlecodersh/ItChat?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge
286 | [py27]: https://img.shields.io/badge/python-2.7-ff69b4.svg
287 | [py35]: https://img.shields.io/badge/python-3.5-red.svg
288 | [english-version]: https://github.com/littlecodersh/ItChat/blob/master/README_EN.md
289 | [itchatmp]: https://github.com/littlecodersh/itchatmp
290 | [document]: https://itchat.readthedocs.org/zh/latest/
291 | [tutorial2]: http://python.jobbole.com/86532/
292 | [robot-source-code]: https://gist.github.com/littlecodersh/ec8ddab12364323c97d4e36459174f0d
293 | [robot-qr]: http://7xrip4.com1.z0.glb.clouddn.com/ItChat%2FQRCode2.jpg?imageView/2/w/400/
294 | [robot-demo-file]: http://7xrip4.com1.z0.glb.clouddn.com/ItChat%2FScreenshots%2F%E5%BE%AE%E4%BF%A1%E8%8E%B7%E5%8F%96%E6%96%87%E4%BB%B6%E5%9B%BE%E7%89%87.png?imageView/2/w/300/
295 | [robot-demo-login]: http://7xrip4.com1.z0.glb.clouddn.com/ItChat%2FScreenshots%2F%E7%99%BB%E5%BD%95%E7%95%8C%E9%9D%A2%E6%88%AA%E5%9B%BE.jpg?imageView/2/w/450/
296 | [littlecodersh]: https://github.com/littlecodersh
297 | [tempdban]: https://github.com/tempdban
298 | [Chyroc]: https://github.com/Chyroc
299 | [youfou-wxpy]: https://github.com/youfou/wxpy
300 | [liuwons-wxBot]: https://github.com/liuwons/wxBot
301 | [zixia-wechaty]: https://github.com/zixia/wechaty
302 | [Mojo-Weixin]: https://github.com/sjdy521/Mojo-Weixin
303 | [HanSon-vbot]: https://github.com/hanson/vbot
304 | [yaphone-itchat4j]: https://github.com/yaphone/itchat4j
305 | [kanjielu-jeeves]: https://github.com/kanjielu/jeeves
306 | [issue#1]: https://github.com/littlecodersh/ItChat/issues/1
307 |
--------------------------------------------------------------------------------
/README.rst:
--------------------------------------------------------------------------------
1 | itchat
2 | ======
3 |
4 | |Python2| |Python3|
5 |
6 | itchat is an open source api for WeChat, a commonly-used Chinese social networking app.
7 |
8 | Accessing your personal wechat account through itchat in python has never been easier.
9 |
10 | A wechat robot can handle all the basic messages with only less than 30 lines of codes.
11 |
12 | And it's similiar to itchatmp (api for wechat massive platform), learn once and get two tools.
13 |
14 | Now Wechat is an important part of personal life, hopefully this repo can help you extend your personal wechat account's functionality and enbetter user's experience with wechat.
15 |
16 | **Installation**
17 |
18 | .. code:: bash
19 |
20 | pip install itchat
21 |
22 | **Simple uses**
23 |
24 | With itchat, if you want to send a message to filehelper, this is how:
25 |
26 | .. code:: python
27 |
28 | import itchat
29 |
30 | itchat.auto_login()
31 |
32 | itchat.send('Hello, filehelper', toUserName='filehelper')
33 |
34 | And you only need to write this to reply personal text messages.
35 |
36 | .. code:: python
37 |
38 | import itchat
39 |
40 | @itchat.msg_register(itchat.content.TEXT)
41 | def text_reply(msg):
42 | return msg.text
43 |
44 | itchat.auto_login()
45 | itchat.run()
46 |
47 | For more advanced uses you may continue on reading or browse the `document `__.
48 |
49 | **Try**
50 |
51 | You may have a try of the robot based on this project first:
52 |
53 | |QRCodeOfRobot|
54 |
55 | Here is the `code `__.
56 |
57 | **Advanced uses**
58 |
59 | *Special usage of message dictionary*
60 |
61 | You may find out that all the users and messages of itchat are dictionaries by printing them out onto the screen.
62 |
63 | But actually they are useful classes itchat created.
64 |
65 | They have useful keys and useful interfaces, like:
66 |
67 | .. code:: python
68 |
69 | @itchat.msg_register(TEXT)
70 | def _(msg):
71 | # equals to print(msg['FromUserName'])
72 | print(msg.fromUserName)
73 |
74 | And like:
75 |
76 | .. code:: python
77 |
78 | author = itchat.search_friends(nickName='LittleCoder')[0]
79 | author.send('greeting, littlecoder!')
80 |
81 | *Message register of various types*
82 |
83 | The following is a demo of how itchat is configured to fetch and reply daily information.
84 |
85 | .. code:: python
86 |
87 | import itchat, time
88 | from itchat.content import *
89 |
90 | @itchat.msg_register([TEXT, MAP, CARD, NOTE, SHARING])
91 | def text_reply(msg):
92 | msg.user.send('%s: %s' % (msg.type, msg.text))
93 |
94 | @itchat.msg_register([PICTURE, RECORDING, ATTACHMENT, VIDEO])
95 | def download_files(msg):
96 | msg.download(msg.fileName)
97 | typeSymbol = {
98 | PICTURE: 'img',
99 | VIDEO: 'vid', }.get(msg.type, 'fil')
100 | return '@%s@%s' % (typeSymbol, msg.fileName)
101 |
102 | @itchat.msg_register(FRIENDS)
103 | def add_friend(msg):
104 | msg.user.verify()
105 | msg.user.send('Nice to meet you!')
106 |
107 | @itchat.msg_register(TEXT, isGroupChat=True)
108 | def text_reply(msg):
109 | if msg.isAt:
110 | msg.user.send(u'@%s\u2005I received: %s' % (
111 | msg.actualNickName, msg.text))
112 |
113 | itchat.auto_login(True)
114 | itchat.run(True)
115 |
116 | *Command line QR Code*
117 |
118 | You can access the QR Code in command line through using this command:
119 |
120 | .. code:: python
121 |
122 | itchat.auto_login(enableCmdQR=True)
123 |
124 | Because of width of some character differs from systems, you may adjust the enableCmdQR to fix the problem.
125 |
126 | .. code:: python
127 |
128 | # for some linux system, width of block character is one instead of two, so enableCmdQR should be 2
129 | itchat.auto_login(enableCmdQR=2)
130 |
131 | Default background color of command line is dark (black), if it's not, you may set enableCmdQR to be negative:
132 |
133 | .. code:: python
134 |
135 | itchat.auto_login(enableCmdQR=-1)
136 |
137 | *Hot reload*
138 |
139 | By using the following command, you may reload the program without re-scan QRCode in some time.
140 |
141 | .. code:: python
142 |
143 | itchat.auto_login(hotReload=True)
144 |
145 | *User search*
146 |
147 | By using `search_friends`, you have four ways to search a user:
148 |
149 | 1. Get your own user information
150 | 2. Get user information through `UserName`
151 | 3. Get user information whose remark name or wechat account or nickname matches name key of the function
152 | 4. Get user information whose remark name, wechat account and nickname match what are given to the function
153 |
154 | Way 3, 4 can be used together, the following is the demo program:
155 |
156 | .. code:: python
157 |
158 | # get your own user information
159 | itchat.search_friends()
160 | # get user information of specific username
161 | itchat.search_friends(userName='@abcdefg1234567')
162 | # get user information of function 3
163 | itchat.search_friends(name='littlecodersh')
164 | # get user information of function 4
165 | itchat.search_friends(wechatAccount='littlecodersh')
166 | # combination of way 3, 4
167 | itchat.search_friends(name='LittleCoder机器人', wechatAccount='littlecodersh')
168 |
169 | There are detailed information about searching and getting of massive platforms and chatrooms in document.
170 |
171 | *Download and send attachments*
172 |
173 | The attachment download function of itchat is in Text key of msg
174 |
175 | Name of the file (default name of picture) is in FileName key of msg
176 |
177 | Download function accept one location value (include the file name) and store attachment accordingly.
178 |
179 | .. code:: python
180 |
181 | @itchat.msg_register([PICTURE, RECORDING, ATTACHMENT, VIDEO])
182 | def download_files(msg):
183 | msg.download(msg.fileName)
184 | itchat.send('@%s@%s' % (
185 | 'img' if msg['Type'] == 'Picture' else 'fil', msg['FileName']),
186 | msg['FromUserName'])
187 | return '%s received' % msg['Type']
188 |
189 | If you don't want a local copy of the picture, you may pass nothing to the function to get a binary string.
190 |
191 | .. code:: python
192 |
193 | @itchat.msg_register([PICTURE, RECORDING, ATTACHMENT, VIDEO])
194 | def download_files(msg):
195 | with open(msg.fileName, 'wb') as f:
196 | f.write(msg.download())
197 |
198 | *Multi instance*
199 |
200 | You may use the following commands to open multi instance.
201 |
202 | .. code:: python
203 |
204 | import itchat
205 |
206 | newInstance = itchat.new_instance()
207 | newInstance.auto_login(hotReload=True, statusStorageDir='newInstance.pkl')
208 |
209 | @newInstance.msg_register(itchat.content.TEXT)
210 | def reply(msg):
211 | return msg['Text']
212 |
213 | newInstance.run()
214 |
215 | *Set callback after login and logout*
216 |
217 | Callback of login and logout are set through `loginCallback` and `exitCallback`.
218 |
219 | .. code:: python
220 |
221 | import time
222 |
223 | import itchat
224 |
225 | def lc():
226 | print('finish login')
227 | def ec():
228 | print('exit')
229 |
230 | itchat.auto_login(loginCallback=lc, exitCallback=ec)
231 | time.sleep(3)
232 | itchat.logout()
233 |
234 | If loginCallback is not set, qr picture will be deleted and cmd will be cleared.
235 |
236 | If you exit through phone, exitCallback will also be called.
237 |
238 | **FAQ**
239 |
240 | Q: Why I can't send files whose name is encoded in utf8?
241 |
242 | A: That's because of the upload setting of requests, you can put `this file `__ (for py3 you need `this `__) into packages/urllib3 of requests package.
243 |
244 | Q: How to use this package to use my wechat as an monitor?
245 |
246 | A: There are two ways: communicate with your own account or with filehelper.
247 |
248 | Q: Why sometimes I can't send messages?
249 |
250 | A: Some account simply can't send messages to yourself, so use `filehelper` instead.
251 |
252 | **Comments**
253 |
254 | If you have any problems or suggestions, you can talk to me in this `issue `__
255 |
256 | Or on `gitter `__.
257 |
258 | .. |QRCodeOfRobot| image:: http://7xrip4.com1.z0.glb.clouddn.com/ItChat%2FQRCode2.jpg?imageView/2/w/200/
259 | .. |Python2| image:: https://img.shields.io/badge/python-2.7-ff69b4.svg
260 | .. |Python3| image:: https://img.shields.io/badge/python-3.5-red.svg
261 |
--------------------------------------------------------------------------------
/README_EN.md:
--------------------------------------------------------------------------------
1 | # itchat
2 |
3 | [![Gitter][gitter-picture]][gitter] ![py27][py27] ![py35][py35] [Chinese version][chinese-version]
4 |
5 | itchat is an open source api for WeChat, a commonly-used Chinese social networking app.
6 |
7 | Accessing your personal wechat account through itchat in python has never been easier.
8 |
9 | A wechat robot can handle all the basic messages with only less than 30 lines of codes.
10 |
11 | And it's similiar to itchatmp (api for wechat massive platform), learn once and get two tools.
12 |
13 | Now Wechat is an important part of personal life, hopefully this repo can help you extend your personal wechat account's functionality and better user's experience with wechat.
14 |
15 | ## Installation
16 |
17 | itchat can be installed with this little one-line command:
18 |
19 | ```python
20 | pip install itchat
21 | ```
22 |
23 | ## Simple uses
24 |
25 | With itchat, if you want to send a message to filehelper, this is how:
26 |
27 | ```python
28 | import itchat
29 |
30 | itchat.auto_login()
31 |
32 | itchat.send('Hello, filehelper', toUserName='filehelper')
33 | ```
34 |
35 | And you only need to write this to reply personal text messages.
36 |
37 | ```python
38 | import itchat
39 |
40 | @itchat.msg_register(itchat.content.TEXT)
41 | def text_reply(msg):
42 | return msg.text
43 |
44 | itchat.auto_login()
45 | itchat.run()
46 | ```
47 |
48 | For more advanced uses you may continue on reading or browse the [document][document].
49 |
50 | ## Have a try
51 |
52 | This QRCode is a wechat account based on the framework of [demo code][robot-source-code]. Seeing is believing, so have a try:)
53 |
54 | ![QRCode][robot-qr]
55 |
56 | ## Screenshots
57 |
58 | ![file-autoreply][robot-demo-file] ![login-page][robot-demo-login]
59 |
60 | ## Advanced uses
61 |
62 | ### Special usage of message dictionary
63 |
64 | You may find out that all the users and messages of itchat are dictionaries by printing them out onto the screen.
65 |
66 | But actually they are useful classes itchat created.
67 |
68 | They have useful keys and useful interfaces, like:
69 |
70 | ```python
71 | @itchat.msg_register(TEXT)
72 | def _(msg):
73 | # equals to print(msg['FromUserName'])
74 | print(msg.fromUserName)
75 | ```
76 |
77 | And like:
78 |
79 | ```python
80 | author = itchat.search_friends(nickName='LittleCoder')[0]
81 | author.send('greeting, littlecoder!')
82 | ```
83 |
84 | ### Message register of various types
85 |
86 | The following is a demo of how itchat is configured to fetch and reply daily information.
87 |
88 | ```python
89 | import itchat, time
90 | from itchat.content import *
91 |
92 | @itchat.msg_register([TEXT, MAP, CARD, NOTE, SHARING])
93 | def text_reply(msg):
94 | msg.user.send('%s: %s' % (msg.type, msg.text))
95 |
96 | @itchat.msg_register([PICTURE, RECORDING, ATTACHMENT, VIDEO])
97 | def download_files(msg):
98 | msg.download(msg.fileName)
99 | typeSymbol = {
100 | PICTURE: 'img',
101 | VIDEO: 'vid', }.get(msg.type, 'fil')
102 | return '@%s@%s' % (typeSymbol, msg.fileName)
103 |
104 | @itchat.msg_register(FRIENDS)
105 | def add_friend(msg):
106 | msg.user.verify()
107 | msg.user.send('Nice to meet you!')
108 |
109 | @itchat.msg_register(TEXT, isGroupChat=True)
110 | def text_reply(msg):
111 | if msg.isAt:
112 | msg.user.send(u'@%s\u2005I received: %s' % (
113 | msg.actualNickName, msg.text))
114 |
115 | itchat.auto_login(True)
116 | itchat.run(True)
117 | ```
118 |
119 | ### Command line QR Code
120 |
121 | You can access the QR Code in command line through using this command:
122 |
123 | ```python
124 | itchat.auto_login(enableCmdQR=True)
125 | ```
126 |
127 | Because of width of some character differs from systems, you may adjust the enableCmdQR to fix the problem.
128 |
129 | ```python
130 | # for some linux system, width of block character is one instead of two, so enableCmdQR should be 2
131 | itchat.auto_login(enableCmdQR=2)
132 | ```
133 |
134 | Default background color of command line is dark (black), if it's not, you may set enableCmdQR to be negative:
135 |
136 | ```python
137 | itchat.auto_login(enableCmdQR=-1)
138 | ```
139 |
140 | ### Hot reload
141 |
142 | By using the following command, you may reload the program without re-scan QRCode in some time.
143 |
144 | ```python
145 | itchat.auto_login(hotReload=True)
146 | ```
147 |
148 | ### User search
149 |
150 | By using `search_friends`, you have four ways to search a user:
151 | 1. Get your own user information
152 | 2. Get user information through `UserName`
153 | 3. Get user information whose remark name or wechat account or nickname matches name key of the function
154 | 4. Get user information whose remark name, wechat account and nickname match what are given to the function
155 |
156 | Way 3, 4 can be used together, the following is the demo program:
157 |
158 | ```python
159 | # get your own user information
160 | itchat.search_friends()
161 | # get user information of specific username
162 | itchat.search_friends(userName='@abcdefg1234567')
163 | # get user information of function 3
164 | itchat.search_friends(name='littlecodersh')
165 | # get user information of function 4
166 | itchat.search_friends(wechatAccount='littlecodersh')
167 | # combination of way 3, 4
168 | itchat.search_friends(name='LittleCoder机器人', wechatAccount='littlecodersh')
169 | ```
170 |
171 | There is detailed information about searching and getting of massive platforms and chatrooms in document.
172 |
173 | ### Download and send attachments
174 |
175 | The attachment download function of itchat is in Text key of msg
176 |
177 | Name of the file (default name of picture) is in FileName key of msg
178 |
179 | Download function accept one location value (include the file name) and store attachment accordingly.
180 |
181 | ```python
182 | @itchat.msg_register([PICTURE, RECORDING, ATTACHMENT, VIDEO])
183 | def download_files(msg):
184 | msg.download(msg.fileName)
185 | itchat.send('@%s@%s' % (
186 | 'img' if msg['Type'] == 'Picture' else 'fil', msg['FileName']),
187 | msg['FromUserName'])
188 | return '%s received' % msg['Type']
189 | ```
190 |
191 | If you don't want a local copy of the picture, you may pass nothing to the function to get a binary string.
192 |
193 | ```python
194 | @itchat.msg_register([PICTURE, RECORDING, ATTACHMENT, VIDEO])
195 | def download_files(msg):
196 | with open(msg.fileName, 'wb') as f:
197 | f.write(msg.download())
198 | ```
199 |
200 | ### Multi instance
201 |
202 | You may use the following commands to open multi instance.
203 |
204 | ```python
205 | import itchat
206 |
207 | newInstance = itchat.new_instance()
208 | newInstance.auto_login(hotReload=True, statusStorageDir='newInstance.pkl')
209 |
210 | @newInstance.msg_register(itchat.content.TEXT)
211 | def reply(msg):
212 | return msg['Text']
213 |
214 | newInstance.run()
215 | ```
216 |
217 | ### Set callback after login and logout
218 |
219 | Callback of login and logout are set through `loginCallback` and `exitCallback`.
220 |
221 | ```python
222 | import time
223 |
224 | import itchat
225 |
226 | def lc():
227 | print('finish login')
228 | def ec():
229 | print('exit')
230 |
231 | itchat.auto_login(loginCallback=lc, exitCallback=ec)
232 | time.sleep(3)
233 | itchat.logout()
234 | ```
235 |
236 | If loginCallback is not set, qr picture will be deleted and cmd will be cleared.
237 |
238 | If you exit through phone, exitCallback will also be called.
239 |
240 | ## FAQ
241 |
242 | Q: How to use this package to use my wechat as an monitor?
243 |
244 | A: There are two ways: communicate with your own account or with filehelper.
245 |
246 | Q: Why sometimes I can't send messages?
247 |
248 | A: Some account simply can't send messages to yourself, so use `filehelper` instead.
249 |
250 | ## Author
251 |
252 | [LittleCoder][littlecodersh]: Structure and py2 py3 version
253 |
254 | [tempdban][tempdban]: Structure and daily maintainance
255 |
256 | [Chyroc][Chyroc]: first py3 version
257 |
258 | ## See also
259 |
260 | [liuwons/wxBot][liuwons-wxBot]: A wechat robot similiar to the robot branch
261 |
262 | [zixia/wechaty][zixia-wechaty]: Wechat for bot in Javascript(ES6), Personal Account Robot Framework/Library
263 |
264 | [sjdy521/Mojo-Weixin][Mojo-Weixin]: Wechat web api in Perl, available with HTTP requests
265 |
266 | [yaphone/itchat4j][yaphone-itchat4j]: Extend your wechat with java
267 |
268 | ## Comments
269 |
270 | If you have any problems or suggestions, feel free to put it up in this [Issue][issue#1].
271 |
272 | Or you may also use [![Gitter][gitter-picture]][gitter]
273 |
274 | [gitter-picture]: https://badges.gitter.im/littlecodersh/ItChat.svg
275 | [gitter]: https://gitter.im/littlecodersh/ItChat?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge
276 | [py27]: https://img.shields.io/badge/python-2.7-ff69b4.svg
277 | [py35]: https://img.shields.io/badge/python-3.5-red.svg
278 | [chinese-version]: https://github.com/littlecodersh/ItChat/blob/master/README.md
279 | [document]: https://itchat.readthedocs.org/zh/latest/
280 | [robot-source-code]: https://gist.github.com/littlecodersh/ec8ddab12364323c97d4e36459174f0d
281 | [robot-qr]: http://7xrip4.com1.z0.glb.clouddn.com/ItChat%2FQRCode2.jpg?imageView/2/w/400/
282 | [robot-demo-file]: http://7xrip4.com1.z0.glb.clouddn.com/ItChat%2FScreenshots%2F%E5%BE%AE%E4%BF%A1%E8%8E%B7%E5%8F%96%E6%96%87%E4%BB%B6%E5%9B%BE%E7%89%87.png?imageView/2/w/300/
283 | [robot-demo-login]: http://7xrip4.com1.z0.glb.clouddn.com/ItChat%2FScreenshots%2F%E7%99%BB%E5%BD%95%E7%95%8C%E9%9D%A2%E6%88%AA%E5%9B%BE.jpg?imageView/2/w/450/
284 | [fields.py-2]: https://gist.github.com/littlecodersh/9a0c5466f442d67d910f877744011705
285 | [fields.py-3]: https://gist.github.com/littlecodersh/e93532d5e7ddf0ec56c336499165c4dc
286 | [littlecodersh]: https://github.com/littlecodersh
287 | [tempdban]: https://github.com/tempdban
288 | [Chyroc]: https://github.com/Chyroc
289 | [liuwons-wxBot]: https://github.com/liuwons/wxBot
290 | [zixia-wechaty]: https://github.com/zixia/wechaty
291 | [Mojo-Weixin]: https://github.com/sjdy521/Mojo-Weixin
292 | [yaphone-itchat4j]: https://github.com/yaphone/itchat4j
293 | [issue#1]: https://github.com/littlecodersh/ItChat/issues/1
294 |
--------------------------------------------------------------------------------
/docs/FAQ.md:
--------------------------------------------------------------------------------
1 | ## 稳定性
2 |
3 | Q: itchat稳定性如何?
4 |
5 | A: 测试用机器人能稳定在线多个月。如果你在测试过程中发现无法稳定登陆,请检查**登陆手机**及主机是否稳定连接网络。如果你需要最稳定的消息环境,建议使用[itchatmp][itchatmp]项目,两者使用方法类似。
6 |
7 | ## 中文文件名文件上传
8 |
9 | Q: 为什么中文的文件没有办法上传?
10 |
11 | A: 这是由于`requests`的编码问题导致的。若需要支持中文文件传输,将[fields.py][fields.py-2](py3版本见[这里][fields.py-3])文件放入requests包的packages/urllib3下即可
12 |
13 | ## 命令行显示二维码
14 |
15 | Q: 为什么我在设定了`itchat.auto_login()`的`enableCmdQR`为`True`后还是没有办法在命令行显示二维码?
16 |
17 | A: 这是由于没有安装可选的包`pillow`,可以使用右边的命令安装:`pip install pillow`
18 |
19 | ## 如何通过itchat实现控制器
20 |
21 | Q: 如何通过这个包将自己的微信号变为控制器?
22 |
23 | A: 有两种方式:发送、接受自己UserName的消息;发送接收文件传输助手(filehelper)的消息
24 |
25 | ## 无法给自己发送消息
26 |
27 | Q: 为什么我发送信息的时候部分信息没有成功发出来?
28 |
29 | A: 有些账号是天生无法给自己的账号发送信息的,建议使用`filehelper`代替。
30 |
31 | [fields.py-2]: https://gist.github.com/littlecodersh/9a0c5466f442d67d910f877744011705
32 | [fields.py-3]: https://gist.github.com/littlecodersh/e93532d5e7ddf0ec56c336499165c4dc
33 | [itchatmp]: https://github.com/littlecodersh/itchatmp
34 |
--------------------------------------------------------------------------------
/docs/api.md:
--------------------------------------------------------------------------------
1 | # API 列表
2 |
3 | 目前API列表暂时没有翻译的版本:
4 |
5 | 最新的API列表可以见core.py。
6 |
7 | ```python
8 | def login(self, enableCmdQR=False, picDir=None, qrCallback=None,
9 | loginCallback=None, exitCallback=None):
10 | ''' log in like web wechat does
11 | for log in
12 | - a QR code will be downloaded and opened
13 | - then scanning status is logged, it paused for you confirm
14 | - finally it logged in and show your nickName
15 | for options
16 | - enableCmdQR: show qrcode in command line
17 | - integers can be used to fit strange char length
18 | - picDir: place for storing qrcode
19 | - qrCallback: method that should accept uuid, status, qrcode
20 | - loginCallback: callback after successfully logged in
21 | - if not set, screen is cleared and qrcode is deleted
22 | - exitCallback: callback after logged out
23 | - it contains calling of logout
24 | for usage
25 | ..code::python
26 |
27 | import itchat
28 | itchat.login()
29 |
30 | it is defined in components/login.py
31 | and of course every single move in login can be called outside
32 | - you may scan source code to see how
33 | - and modified according to your own demond
34 | '''
35 | raise NotImplementedError()
36 | def get_QRuuid(self):
37 | ''' get uuid for qrcode
38 | uuid is the symbol of qrcode
39 | - for logging in, you need to get a uuid first
40 | - for downloading qrcode, you need to pass uuid to it
41 | - for checking login status, uuid is also required
42 | if uuid has timed out, just get another
43 | it is defined in components/login.py
44 | '''
45 | raise NotImplementedError()
46 | def get_QR(self, uuid=None, enableCmdQR=False, picDir=None, qrCallback=None):
47 | ''' download and show qrcode
48 | for options
49 | - uuid: if uuid is not set, latest uuid you fetched will be used
50 | - enableCmdQR: show qrcode in cmd
51 | - picDir: where to store qrcode
52 | - qrCallback: method that should accept uuid, status, qrcode
53 | it is defined in components/login.py
54 | '''
55 | raise NotImplementedError()
56 | def check_login(self, uuid=None):
57 | ''' check login status
58 | for options:
59 | - uuid: if uuid is not set, latest uuid you fetched will be used
60 | for return values:
61 | - a string will be returned
62 | - for meaning of return values
63 | - 200: log in successfully
64 | - 201: waiting for press confirm
65 | - 408: uuid timed out
66 | - 0 : unknown error
67 | for processing:
68 | - syncUrl and fileUrl is set
69 | - BaseRequest is set
70 | blocks until reaches any of above status
71 | it is defined in components/login.py
72 | '''
73 | raise NotImplementedError()
74 | def web_init(self):
75 | ''' get info necessary for initializing
76 | for processing:
77 | - own account info is set
78 | - inviteStartCount is set
79 | - syncKey is set
80 | - part of contact is fetched
81 | it is defined in components/login.py
82 | '''
83 | raise NotImplementedError()
84 | def show_mobile_login(self):
85 | ''' show web wechat login sign
86 | the sign is on the top of mobile phone wechat
87 | sign will be added after sometime even without calling this function
88 | it is defined in components/login.py
89 | '''
90 | raise NotImplementedError()
91 | def start_receiving(self, finishCallback=None):
92 | ''' open a thread for heart loop and receiving messages
93 | for options:
94 | - finishCallback: callback after logged out
95 | - it contains calling of logout
96 | for processing:
97 | - messages: msgs are formatted and passed on to registered fns
98 | - contact : chatrooms are updated when related info is received
99 | it is defined in components/login.py
100 | '''
101 | raise NotImplementedError()
102 | def get_msg(self):
103 | ''' fetch messages
104 | for fetching
105 | - method blocks for sometime until
106 | - new messages are to be received
107 | - or anytime they like
108 | - synckey is updated with returned synccheckkey
109 | it is defined in components/login.py
110 | '''
111 | raise NotImplementedError()
112 | def logout(self):
113 | ''' logout
114 | if core is now alive
115 | logout will tell wechat backstage to logout
116 | and core gets ready for another login
117 | it is defined in components/login.py
118 | '''
119 | raise NotImplementedError()
120 | def update_chatroom(self, userName, detailedMember=False):
121 | ''' update chatroom
122 | for chatroom contact
123 | - a chatroom contact need updating to be detailed
124 | - detailed means members, encryid, etc
125 | - auto updating of heart loop is a more detailed updating
126 | - member uin will also be filled
127 | - once called, updated info will be stored
128 | for options
129 | - userName: 'UserName' key of chatroom or a list of it
130 | - detailedMember: whether to get members of contact
131 | it is defined in components/contact.py
132 | '''
133 | raise NotImplementedError()
134 | def update_friend(self, userName):
135 | ''' update chatroom
136 | for friend contact
137 | - once called, updated info will be stored
138 | for options
139 | - userName: 'UserName' key of a friend or a list of it
140 | it is defined in components/contact.py
141 | '''
142 | raise NotImplementedError()
143 | def get_contact(self, update=False):
144 | ''' fetch part of contact
145 | for part
146 | - all the massive platforms and friends are fetched
147 | - if update, only starred chatrooms are fetched
148 | for options
149 | - update: if not set, local value will be returned
150 | for results
151 | - chatroomList will be returned
152 | it is defined in components/contact.py
153 | '''
154 | raise NotImplementedError()
155 | def get_friends(self, update=False):
156 | ''' fetch friends list
157 | for options
158 | - update: if not set, local value will be returned
159 | for results
160 | - a list of friends' info dicts will be returned
161 | it is defined in components/contact.py
162 | '''
163 | raise NotImplementedError()
164 | def get_chatrooms(self, update=False, contactOnly=False):
165 | ''' fetch chatrooms list
166 | for options
167 | - update: if not set, local value will be returned
168 | - contactOnly: if set, only starred chatrooms will be returned
169 | for results
170 | - a list of chatrooms' info dicts will be returned
171 | it is defined in components/contact.py
172 | '''
173 | raise NotImplementedError()
174 | def get_mps(self, update=False):
175 | ''' fetch massive platforms list
176 | for options
177 | - update: if not set, local value will be returned
178 | for results
179 | - a list of platforms' info dicts will be returned
180 | it is defined in components/contact.py
181 | '''
182 | raise NotImplementedError()
183 | def set_alias(self, userName, alias):
184 | ''' set alias for a friend
185 | for options
186 | - userName: 'UserName' key of info dict
187 | - alias: new alias
188 | it is defined in components/contact.py
189 | '''
190 | raise NotImplementedError()
191 | def set_pinned(self, userName, isPinned=True):
192 | ''' set pinned for a friend or a chatroom
193 | for options
194 | - userName: 'UserName' key of info dict
195 | - isPinned: whether to pin
196 | it is defined in components/contact.py
197 | '''
198 | raise NotImplementedError()
199 | def add_friend(self, userName, status=2, verifyContent='', autoUpdate=True):
200 | ''' add a friend or accept a friend
201 | for options
202 | - userName: 'UserName' for friend's info dict
203 | - status:
204 | - for adding status should be 2
205 | - for accepting status should be 3
206 | - ticket: greeting message
207 | - userInfo: friend's other info for adding into local storage
208 | it is defined in components/contact.py
209 | '''
210 | raise NotImplementedError()
211 | def get_head_img(self, userName=None, chatroomUserName=None, picDir=None):
212 | ''' place for docs
213 | for options
214 | - if you want to get chatroom header: only set chatroomUserName
215 | - if you want to get friend header: only set userName
216 | - if you want to get chatroom member header: set both
217 | it is defined in components/contact.py
218 | '''
219 | raise NotImplementedError()
220 | def create_chatroom(self, memberList, topic=''):
221 | ''' create a chatroom
222 | for creating
223 | - its calling frequency is strictly limited
224 | for options
225 | - memberList: list of member info dict
226 | - topic: topic of new chatroom
227 | it is defined in components/contact.py
228 | '''
229 | raise NotImplementedError()
230 | def set_chatroom_name(self, chatroomUserName, name):
231 | ''' set chatroom name
232 | for setting
233 | - it makes an updating of chatroom
234 | - which means detailed info will be returned in heart loop
235 | for options
236 | - chatroomUserName: 'UserName' key of chatroom info dict
237 | - name: new chatroom name
238 | it is defined in components/contact.py
239 | '''
240 | raise NotImplementedError()
241 | def delete_member_from_chatroom(self, chatroomUserName, memberList):
242 | ''' deletes members from chatroom
243 | for deleting
244 | - you can't delete yourself
245 | - if so, no one will be deleted
246 | - strict-limited frequency
247 | for options
248 | - chatroomUserName: 'UserName' key of chatroom info dict
249 | - memberList: list of members' info dict
250 | it is defined in components/contact.py
251 | '''
252 | raise NotImplementedError()
253 | def add_member_into_chatroom(self, chatroomUserName, memberList,
254 | useInvitation=False):
255 | ''' add members into chatroom
256 | for adding
257 | - you can't add yourself or member already in chatroom
258 | - if so, no one will be added
259 | - if member will over 40 after adding, invitation must be used
260 | - strict-limited frequency
261 | for options
262 | - chatroomUserName: 'UserName' key of chatroom info dict
263 | - memberList: list of members' info dict
264 | - useInvitation: if invitation is not required, set this to use
265 | it is defined in components/contact.py
266 | '''
267 | raise NotImplementedError()
268 | def send_raw_msg(self, msgType, content, toUserName):
269 | ''' many messages are sent in a common way
270 | for demo
271 | .. code:: python
272 |
273 | @itchat.msg_register(itchat.content.CARD)
274 | def reply(msg):
275 | itchat.send_raw_msg(msg['MsgType'], msg['Content'], msg['FromUserName'])
276 |
277 | there are some little tricks here, you may discover them yourself
278 | but remember they are tricks
279 | it is defined in components/messages.py
280 | '''
281 | raise NotImplementedError()
282 | def send_msg(self, msg='Test Message', toUserName=None):
283 | ''' send plain text message
284 | for options
285 | - msg: should be unicode if there's non-ascii words in msg
286 | - toUserName: 'UserName' key of friend dict
287 | it is defined in components/messages.py
288 | '''
289 | raise NotImplementedError()
290 | def upload_file(self, fileDir, isPicture=False, isVideo=False):
291 | ''' upload file to server and get mediaId
292 | for options
293 | - fileDir: dir for file ready for upload
294 | - isPicture: whether file is a picture
295 | - isVideo: whether file is a video
296 | for return values
297 | will return a ReturnValue
298 | if succeeded, mediaId is in r['MediaId']
299 | it is defined in components/messages.py
300 | '''
301 | raise NotImplementedError()
302 | def send_file(self, fileDir, toUserName=None, mediaId=None):
303 | ''' send attachment
304 | for options
305 | - fileDir: dir for file ready for upload
306 | - mediaId: mediaId for file.
307 | - if set, file will not be uploaded twice
308 | - toUserName: 'UserName' key of friend dict
309 | it is defined in components/messages.py
310 | '''
311 | raise NotImplementedError()
312 | def send_image(self, fileDir, toUserName=None, mediaId=None):
313 | ''' send image
314 | for options
315 | - fileDir: dir for file ready for upload
316 | - if it's a gif, name it like 'xx.gif'
317 | - mediaId: mediaId for file.
318 | - if set, file will not be uploaded twice
319 | - toUserName: 'UserName' key of friend dict
320 | it is defined in components/messages.py
321 | '''
322 | raise NotImplementedError()
323 | def send_video(self, fileDir=None, toUserName=None, mediaId=None):
324 | ''' send video
325 | for options
326 | - fileDir: dir for file ready for upload
327 | - if mediaId is set, it's unnecessary to set fileDir
328 | - mediaId: mediaId for file.
329 | - if set, file will not be uploaded twice
330 | - toUserName: 'UserName' key of friend dict
331 | it is defined in components/messages.py
332 | '''
333 | raise NotImplementedError()
334 | def send(self, msg, toUserName=None, mediaId=None):
335 | ''' wrapped function for all the sending functions
336 | for options
337 | - msg: message starts with different string indicates different type
338 | - list of type string: ['@fil@', '@img@', '@msg@', '@vid@']
339 | - they are for file, image, plain text, video
340 | - if none of them matches, it will be sent like plain text
341 | - toUserName: 'UserName' key of friend dict
342 | - mediaId: if set, uploading will not be repeated
343 | it is defined in components/messages.py
344 | '''
345 | raise NotImplementedError()
346 | def dump_login_status(self, fileDir=None):
347 | ''' dump login status to a specific file
348 | for option
349 | - fileDir: dir for dumping login status
350 | it is defined in components/hotreload.py
351 | '''
352 | raise NotImplementedError()
353 | def load_login_status(self, fileDir,
354 | loginCallback=None, exitCallback=None):
355 | ''' load login status from a specific file
356 | for option
357 | - fileDir: file for loading login status
358 | - loginCallback: callback after successfully logged in
359 | - if not set, screen is cleared and qrcode is deleted
360 | - exitCallback: callback after logged out
361 | - it contains calling of logout
362 | it is defined in components/hotreload.py
363 | '''
364 | raise NotImplementedError()
365 | def auto_login(self, hotReload=False, statusStorageDir='itchat.pkl',
366 | enableCmdQR=False, picDir=None, qrCallback=None,
367 | loginCallback=None, exitCallback=None):
368 | ''' log in like web wechat does
369 | for log in
370 | - a QR code will be downloaded and opened
371 | - then scanning status is logged, it paused for you confirm
372 | - finally it logged in and show your nickName
373 | for options
374 | - hotReload: enable hot reload
375 | - statusStorageDir: dir for storing log in status
376 | - enableCmdQR: show qrcode in command line
377 | - integers can be used to fit strange char length
378 | - picDir: place for storing qrcode
379 | - loginCallback: callback after successfully logged in
380 | - if not set, screen is cleared and qrcode is deleted
381 | - exitCallback: callback after logged out
382 | - it contains calling of logout
383 | - qrCallback: method that should accept uuid, status, qrcode
384 | for usage
385 | ..code::python
386 |
387 | import itchat
388 | itchat.auto_login()
389 |
390 | it is defined in components/register.py
391 | and of course every single move in login can be called outside
392 | - you may scan source code to see how
393 | - and modified according to your own demond
394 | '''
395 | raise NotImplementedError()
396 | def configured_reply(self):
397 | ''' determine the type of message and reply if its method is defined
398 | however, I use a strange way to determine whether a msg is from massive platform
399 | I haven't found a better solution here
400 | The main problem I'm worrying about is the mismatching of new friends added on phone
401 | If you have any good idea, pleeeease report an issue. I will be more than grateful.
402 | '''
403 | raise NotImplementedError()
404 | def msg_register(self, msgType,
405 | isFriendChat=False, isGroupChat=False, isMpChat=False):
406 | ''' a decorator constructor
407 | return a specific decorator based on information given
408 | '''
409 | raise NotImplementedError()
410 | def run(self, debug=True):
411 | ''' start auto respond
412 | for option
413 | - debug: if set, debug info will be shown on screen
414 | it is defined in components/register.py
415 | '''
416 | raise NotImplementedError()
417 | def search_friends(self, name=None, userName=None, remarkName=None, nickName=None,
418 | wechatAccount=None):
419 | return self.storageClass.search_friends(name, userName, remarkName,
420 | nickName, wechatAccount)
421 | def search_chatrooms(self, name=None, userName=None):
422 | return self.storageClass.search_chatrooms(name, userName)
423 | def search_mps(self, name=None, userName=None):
424 | return self.storageClass.search_mps(name, userName)
425 | ```
426 |
--------------------------------------------------------------------------------
/docs/bootstrap/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/littlecodersh/ItChat/d5ce5db32ca15cef8eefa548a438a9fcc4502a6d/docs/bootstrap/__init__.py
--------------------------------------------------------------------------------
/docs/bootstrap/base.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {%- block site_meta %}
5 |
6 |
7 |
8 | {% if config.site_description %}{% endif %}
9 | {% if config.site_author %}{% endif %}
10 | {% if page.canonical_url %}{% endif %}
11 |
12 | {%- endblock %}
13 |
14 | {%- block htmltitle %}
15 | {% if page and page.title %}{{ page.title }} - {% endif %}{{ config.site_name }}
16 | {%- endblock %}
17 |
18 | {%- block styles %}
19 |
20 |
21 |
22 |
23 | {%- for path in extra_css %}
24 |
25 | {%- endfor %}
26 | {%- endblock %}
27 |
28 | {%- block libs %}
29 |
30 |
34 |
35 |
36 |
37 |
38 | {%- endblock %}
39 |
40 | {%- block analytics %}
41 | {% if config.google_analytics %}
42 |
51 | {% endif %}
52 | {%- endblock %}
53 |
54 | {%- block extrahead %} {% endblock %}
55 |
56 |
57 |
58 |
59 | {% include "nav.html" %}
60 |
61 |