Skip to content

Commit

Permalink
Fix char width bug of QRCode & update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
littlecodersh committed Jul 24, 2016
1 parent c1a52e2 commit a727f21
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 7 deletions.
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

使用不到三十行的代码,你就可以完成一个能够处理所有信息的微信机器人。

Expand Down Expand Up @@ -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),百闻不如一见,有兴趣可以尝试一下。
Expand Down
43 changes: 43 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -54,6 +56,45 @@ Here is the `code <https://github.com/littlecodersh/ItChat/tree/robot>`__.
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?
Expand All @@ -72,3 +113,5 @@ If you have any problems or suggestions, you can talk to me in this `issue <http
Or on `gitter <https://badges.gitter.im/littlecodersh/ItChat.svg>`__.

.. |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
41 changes: 39 additions & 2 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/).
Expand Down Expand Up @@ -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:)
Expand Down
49 changes: 45 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -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)

使用不到三十行的代码,你就可以完成一个能够处理所有信息的微信机器人。

Expand Down Expand Up @@ -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),百闻不如一见,有兴趣可以尝试一下。
Expand All @@ -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版本。
Expand Down

0 comments on commit a727f21

Please sign in to comment.