diff --git a/README.md b/README.md index eeafd5f5..bf4c7506 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ itchat是一个开源的微信个人号接口,使用他你可以轻松的通过命令行使用个人微信号。 -微信机器人的实现及命令行版微信见[robot分支](https://github.com/littlecodersh/ItChat/tree/robot),Python 3.5.1 的版本可见这里:[here](https://github.com/littlecodersh/ItChat/tree/py3-dev)。 +微信机器人的实现及命令行版微信见[robot分支](https://github.com/littlecodersh/ItChat/tree/robot)。 使用不到三十行的代码,你就可以完成一个能够处理所有信息的微信机器人。 @@ -56,6 +56,45 @@ itchat.auto_login() itchat.run() ``` +## Advanced uses + +### 命令行二维码 + +通过以下命令可以在登陆的时候使用命令行显示二维码: + +```python +itchat.auto_login(enableCmdQR = True) +``` + +部分系统可能字幅宽度有出入,可以通过将enableCmdQR赋值为特定的倍数进行调整: + +```python +# 如部分的linux系统,块字符的宽度为一个字符(正常应为两字符),故赋值为2 +itchat.auto_login(enableCmdQR = 2) +``` + +### 退出程序后暂存登陆状态 + +通过如下命令登陆,即使程序关闭,一定时间内重新开启也可以不用重新扫码。 + +```python +itchat.auto_login(hotReload = True) +``` + +### 附件的下载与发送 + +itchat的附件下载方法存储在msg的Text键中。 + +下载方法接受一个可用的位置参数(包括文件名),并将文件相应的存储。 + +```python +@itchat.msg_register(['Picture', 'Recording', 'Attachment', 'Video']) +def download_files(msg): + msg['Text'](msg['FileName']) + itchat.send('%s received'%msg['Type'], msg['FromUserName']) + itchat.send('@%s@%s'%('img' if msg['Type'] == 'Picture' else 'fil', fileDir), msg['FromUserName']) +``` + ## Have a try 这是一个基于这一项目的[开源小机器人](https://github.com/littlecodersh/ItChat/tree/robot),百闻不如一见,有兴趣可以尝试一下。 diff --git a/README.rst b/README.rst index 97081d49..48f7f589 100644 --- a/README.rst +++ b/README.rst @@ -1,6 +1,8 @@ itchat ====== +|Python2| |Python3| + itchat is a open souce wechat api project for personal account. It enables you to access your personal wechat account through command line. @@ -54,6 +56,45 @@ Here is the `code `__. itchat.auto_login() itchat.run() +**Advanced uses** + +*Command line QR Code* + +You can access the QR Code in command line through using this command: + +.. code:: python + + itchat.auto_login(enableCmdQR = True) + +Because of width of some character differs from systems, you may adjust the enableCmdQR to fix the problem. + +.. code:: python + + # for some linux system, width of block character is one instead of two, so enableCmdQR should be 2 + itchat.auto_login(enableCmdQR = 2) + +*Hot reload* + +By using the following command, you may reload the program without re-scan QRCode in some time. + +.. code:: python + + itchat.auto_login(hotReload = True) + +*Download and send attachments* + +The attachment download function of itchat is in Text key of msg + +Download function accept one location value (include the file name) and store attachment accordingly. + +.. code:: python + + @itchat.msg_register(['Picture', 'Recording', 'Attachment', 'Video']) + def download_files(msg): + msg['Text'](msg['FileName']) + itchat.send('%s received'%msg['Type'], msg['FromUserName']) + itchat.send('@%s@%s'%('img' if msg['Type'] == 'Picture' else 'fil', fileDir), msg['FromUserName']) + **FAQ** Q: Why I can't send files whose name is encoded in utf8? @@ -72,3 +113,5 @@ If you have any problems or suggestions, you can talk to me in this `issue `__. .. |QRCodeOfRobot| image:: http://7xrip4.com1.z0.glb.clouddn.com/ItChat%2FQRCode2.jpg?imageView/2/w/200/ +.. |Python2| image:: https://img.shields.io/badge/python-2.7-ff69b4.svg +.. |Python3| image:: https://img.shields.io/badge/python-3.5-red.svg diff --git a/README_EN.md b/README_EN.md index 2eabdc01..bb1c6722 100644 --- a/README_EN.md +++ b/README_EN.md @@ -10,8 +10,6 @@ A wechat robot can handle all the basic messages with only less than 30 lines of 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. -Python 2.7.11 version is also available [here](https://github.com/littlecodersh/ItChat/tree/py3-dev). - ## Documents You may get the document of this api from [here](https://itchat.readthedocs.org/zh/latest/). @@ -57,6 +55,45 @@ itchat.auto_login() itchat.run() ``` +## Advanced uses + +### Command line QR Code + +You can access the QR Code in command line through using this command: + +```python +itchat.auto_login(enableCmdQR = True) +``` + +Because of width of some character differs from systems, you may adjust the enableCmdQR to fix the problem. + +```python +# for some linux system, width of block character is one instead of two, so enableCmdQR should be 2 +itchat.auto_login(enableCmdQR = 2) +``` + +### Hot reload + +By using the following command, you may reload the program without re-scan QRCode in some time. + +```python +itchat.auto_login(hotReload = True) +``` + +### Download and send attachments + +The attachment download function of itchat is in Text key of msg + +Download function accept one location value (include the file name) and store attachment accordingly. + +```python +@itchat.msg_register(['Picture', 'Recording', 'Attachment', 'Video']) +def download_files(msg): + msg['Text'](msg['FileName']) + itchat.send('%s received'%msg['Type'], msg['FromUserName']) + itchat.send('@%s@%s'%('img' if msg['Type'] == 'Picture' else 'fil', fileDir), msg['FromUserName']) +``` + ## Have a try This QRCode is a wechat account based on the framework of [robot branch](https://github.com/littlecodersh/ItChat/tree/robot). Seeing is believing, so have a try:) diff --git a/docs/index.md b/docs/index.md index fc6021fb..bf4c7506 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,10 +1,10 @@ # itchat -[![Gitter](https://badges.gitter.im/littlecodersh/ItChat.svg)](https://gitter.im/littlecodersh/ItChat?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) ![python](https://img.shields.io/badge/python-2.7-ff69b4.svg) [English version](https://github.com/littlecodersh/ItChat/blob/master/README_EN.md) +[![Gitter](https://badges.gitter.im/littlecodersh/ItChat.svg)](https://gitter.im/littlecodersh/ItChat?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) ![python](https://img.shields.io/badge/python-2.7-ff69b4.svg) ![python](https://img.shields.io/badge/python-3.5-red.svg) [English version](https://github.com/littlecodersh/ItChat/blob/master/README_EN.md) itchat是一个开源的微信个人号接口,使用他你可以轻松的通过命令行使用个人微信号。 -微信机器人的实现及命令行版微信见[robot分支](https://github.com/littlecodersh/ItChat/tree/robot),Python 3.5.1 的版本可见这里:[here](https://github.com/littlecodersh/ItChat/tree/py3-dev)。 +微信机器人的实现及命令行版微信见[robot分支](https://github.com/littlecodersh/ItChat/tree/robot)。 使用不到三十行的代码,你就可以完成一个能够处理所有信息的微信机器人。 @@ -53,11 +53,48 @@ def text_reply(msg): itchat.send(u'@%s\u2005I received: %s'%(msg['ActualNickName'], msg['Content']), msg['FromUserName']) itchat.auto_login() -# if you don't want to use hot reload, you may use the following login command instead -# itchat.auto_login(hotReload = False) itchat.run() ``` +## Advanced uses + +### 命令行二维码 + +通过以下命令可以在登陆的时候使用命令行显示二维码: + +```python +itchat.auto_login(enableCmdQR = True) +``` + +部分系统可能字幅宽度有出入,可以通过将enableCmdQR赋值为特定的倍数进行调整: + +```python +# 如部分的linux系统,块字符的宽度为一个字符(正常应为两字符),故赋值为2 +itchat.auto_login(enableCmdQR = 2) +``` + +### 退出程序后暂存登陆状态 + +通过如下命令登陆,即使程序关闭,一定时间内重新开启也可以不用重新扫码。 + +```python +itchat.auto_login(hotReload = True) +``` + +### 附件的下载与发送 + +itchat的附件下载方法存储在msg的Text键中。 + +下载方法接受一个可用的位置参数(包括文件名),并将文件相应的存储。 + +```python +@itchat.msg_register(['Picture', 'Recording', 'Attachment', 'Video']) +def download_files(msg): + msg['Text'](msg['FileName']) + itchat.send('%s received'%msg['Type'], msg['FromUserName']) + itchat.send('@%s@%s'%('img' if msg['Type'] == 'Picture' else 'fil', fileDir), msg['FromUserName']) +``` + ## Have a try 这是一个基于这一项目的[开源小机器人](https://github.com/littlecodersh/ItChat/tree/robot),百闻不如一见,有兴趣可以尝试一下。 @@ -74,6 +111,10 @@ Q: 为什么中文的文件没有办法上传? A: 这是由于`requests`的编码问题导致的。若需要支持中文文件传输,将[fields.py](https://github.com/littlecodersh/ItChat/blob/robot/plugin/config/fields.py)文件放入requests包的packages/urllib3下即可 +Q: 为什么我在设定了`itchat.auto_login()`的`enableCmdQR`为`True`后还是没有办法在命令行显示二维码? + +A: 这是由于没有安装可选的包`pillow`,可以使用右边的命令安装:`pip install pillow` + ## Author [LittleCoder](https://github.com/littlecodersh): 整体构架及完成Python2版本。