Skip to content

Commit

Permalink
Merge pull request #263 from whtsky/develop
Browse files Browse the repository at this point in the history
Release 1.2.0
  • Loading branch information
whtsky committed Dec 11, 2017
2 parents a9d0376 + 459d34c commit ae9180a
Show file tree
Hide file tree
Showing 100 changed files with 2,024 additions and 4,181 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
@@ -0,0 +1,10 @@
root = true

[*]
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true

[{.travis.yml,appveyor.yml,*.ini}]
indent_size = 2
4 changes: 3 additions & 1 deletion .flake8
@@ -1,9 +1,11 @@
[flake8]
max-line-length = 100
ignore = E722
max-complexity = 12
exclude =
.git,
__pycache__,
docs,
travis,
venv
venv,
tests/fake_sae.py
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -63,4 +63,3 @@ pip-selfcheck.json
venv

*.sqlite3
/.vscode
23 changes: 5 additions & 18 deletions .travis.yml
@@ -1,33 +1,20 @@
os: osx
language: generic
osx_image: xcode8.2
env:
- PYTHON_VERSION=2 PYTHON_INSTALL_METHOD=system
matrix:
include:
- env:
- PYTHON_MAJOR=py3
- PYTHON_VERSION="3.6.0 3.5.2 3.4.5"
- PYTHON_INSTALL_METHOD=tox
- PYTHON_MAJOR="py34|py35"
- PYTHON_VERSION="3.5.2 3.4.5"
- env:
- PYTHON_MAJOR="py36"
- PYTHON_VERSION="3.6.2"
- env:
- PYTHON_MAJOR=py2
- PYTHON_VERSION="2.7.12"
- PYTHON_INSTALL_METHOD=tox
- env:
- PYTHON_MAJOR=pypy
- PYTHON_VERSION="pypy-5.0.0"
- PYTHON_INSTALL_METHOD=tox
- env:
- PYTHON_VERSION=2.7
- PYTHON_INSTALL_METHOD=macpython
- env:
- PYTHON_VERSION=3.4
- PYTHON_INSTALL_METHOD=macpython
- env:
- PYTHON_VERSION=3.5
- PYTHON_INSTALL_METHOD=macpython
- osx_image: xcode8
- osx_image: xcode6.4
cache:
directories:
- $HOME/.pyenv
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
@@ -0,0 +1,3 @@
{
"python.linting.flake8Enabled": true
}
7 changes: 7 additions & 0 deletions appveyor.yml
Expand Up @@ -4,6 +4,7 @@ cache:
- '%LOCALAPPDATA%\pip\Cache'
services:
- mongodb
- mysql
init:
- "ECHO %PYTHON% %PYTHON_VERSION% %PYTHON_ARCH%"
- ps: "ls C:/Python*"
Expand All @@ -12,6 +13,12 @@ install:
- choco install redis-64
- redis-server --service-install
- redis-server --service-start
- set DATABASE_MYSQL_USERNAME=root
- set DATABASE_MYSQL_PASSWORD=Password12!
before_test:
- ps: $env:MYSQL_PWD="Password12!"
- ps: $cmd = '"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql" -e "create database werobot;" --user=root'
- ps: iex "& $cmd"
test_script:
- C:\Python35\python -m tox -c tox-win.ini
on_success:
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
@@ -1,4 +1,4 @@
-r tox-requirements.txt
flake8==2.6.2
flake8==3.5.0
tox
django
4 changes: 4 additions & 0 deletions docs/_themes/flask/static/flasky.css_t
Expand Up @@ -311,6 +311,10 @@ table.field-list th {
padding: 0 0.8em 0 0;
}

table.field-list th.field-name {
width: 3rem;
}

table.field-list td {
padding: 0;
}
Expand Down
45 changes: 45 additions & 0 deletions docs/api.rst
@@ -0,0 +1,45 @@
API
==========

.. module:: werobot

应用对象
------------

.. module:: werobot.robot
.. autoclass:: BaseRoBot
:members:
.. autoclass:: WeRoBot
:members:

配置对象
------------

.. module:: werobot.config
.. autoclass:: Config
:members:

Session 对象
------------
.. module:: werobot.session.sqlitestorage
.. autoclass:: SQLiteStorage

.. module:: werobot.session.filestorage
.. autoclass:: FileStorage

.. module:: werobot.session.mongodbstorage
.. autoclass:: MongoDBStorage

.. module:: werobot.session.redisstorage
.. autoclass:: RedisStorage

.. module:: werobot.session.saekvstorage
.. autoclass:: SaeKVDBStorage

.. module:: werobot.session.mysqlstorage
.. autoclass:: MySQLStorage

log
------------
.. module:: werobot.logger
.. autofunction:: enable_pretty_logging
16 changes: 16 additions & 0 deletions docs/changelog.rst
@@ -1,6 +1,22 @@
Changelog
=============

Version 1.2.0
----------------
+ 增加 :class:`werobot.session.mysqlstorage.MySQLStorage`
+ 增加 :class:`werobot.messages.events.ScanCodePushEvent`
+ 增加 :class:`werobot.messages.events.ScanCodeWaitMsgEvent`
+ 增加 :func:`werobot.robot.BaseRoBot.add_filter`
+ :func:`werobot.utils.generate_token` 在 Python 3.6+ 下优先使用 ``secrets.choice`` 来随机生成 token
+ 修复 :func:`werobot.client.Client.get_media_list` 的调用参数错误 (`#208 <https://github.com/whtsky/WeRoBot/issues/208>`_)
+ 修复了某些情况下 Client 中文编码不正确的问题 (`#250 <https://github.com/whtsky/WeRoBot/issues/250>`_)
+ Handler 中的 Exception 现在会以 Error level 记录到 logger 中
+ 在文档中增加了独立的 :doc:`api` 部分
+ 添加了 ``video`` 和 ``shortvideo`` 的修饰器
+ 增加了 :class:`werobot.session.saekvstorage.SaeKVDBStorage` 的测试
+ 增加了对 Django 2.0 的测试
+ 抛弃对 Django < 1.8 、 Django 1.9 、 Django 1.10 的支持

Version 1.1.1
----------------

Expand Down
12 changes: 12 additions & 0 deletions docs/client.rst
Expand Up @@ -176,3 +176,15 @@
详细请参考 http://mp.weixin.qq.com/wiki/15/8386c11b7bc4cdd1499c572bfe2e95b3.html

.. automethod:: Client.get_media_list


返回码都是什么意思?
--------------------------

参考 https://mp.weixin.qq.com/wiki/10/6380dc743053a91c544ffd2b7c959166.html

48001 -- API Unauthorized
---------------------------

如果你遇到了这个错误,请检查你的微信公众号是否有调用该接口的权限。
参考: https://mp.weixin.qq.com/wiki/13/8d4957b72037e3308a0ca1b21f25ae8d.html
14 changes: 3 additions & 11 deletions docs/config.rst
@@ -1,9 +1,9 @@
Config
=====================

WeRoBot 使用 ``WeRoBot.Config`` 类来存储配置信息。 ``WeRoBot`` 类实例的 ``config`` 属性是一个 :class:`WeRobot.config.Config` 实例。
WeRoBot 使用 ``WeRoBot.Config`` 类来存储配置信息。 ``WeRoBot`` 类实例的 ``config`` 属性是一个 :class:`werobot.config.Config` 实例。

:class:`WeRobot.config.Config` 继承自 `dict` 。因此, 你可以像使用普通 dict 一样使用它 ::
:class:`~werobot.config.Config` 继承自 `dict` 。因此, 你可以像使用普通 dict 一样使用它 ::

from werobot import WeRoBot
robot = WeRoBot(token='2333')
Expand All @@ -24,7 +24,7 @@ WeRoBot 使用 ``WeRoBot.Config`` 类来存储配置信息。 ``WeRoBot`` 类

.. note:: 如果你在初始化 ``WeRoBot`` 时传入了 ``config`` 参数, ``WeRoBot`` 会忽略除 ``logger`` 外其他所有的初始化参数。 如果你需要对 ``WeRoBot`` 进行一些配置操作, 请修改 Config 。

与普通 `dict` 不同的是, 你可以先把配置文件保存在一个对象或是文件中, 然后在 :class:`WeRoBot.config.Config` 中导入配置 ::
与普通 `dict` 不同的是, 你可以先把配置文件保存在一个对象或是文件中, 然后在 :class:`~werobot.config.Config` 中导入配置 ::

from werobot import WeRoBot
robot = WeRoBot(token='2333')
Expand Down Expand Up @@ -53,11 +53,3 @@ WeRoBot 使用 ``WeRoBot.Config`` 类来存储配置信息。 ``WeRoBot`` 类
APP_SECRET=None,
ENCODING_AES_KEY=None
)
API
----------

.. module:: werobot.config
.. autoclass:: Config
:members:
30 changes: 15 additions & 15 deletions docs/contrib.rst
Expand Up @@ -5,29 +5,29 @@ WeRoBot 可以作为独立服务运行,也可以集成在其他 Web 框架中

Django
--------
WeRoBot 支持 Django 1.6+。
WeRoBot 支持 Django 1.8+。

首先,在一个文件中写好你的微信机器人 ::

# Filename: robot.py

from werobot import WeRoBot

robot = WeRoBot(token='token')
myrobot = WeRoBot(token='token')


@robot.handler
@myrobot.handler
def hello(message):
return 'Hello World!'

然后,在你 Django 项目中的 ``urls.py`` 中调用 :func:`werobot.contrib.django.make_view` ,将 WeRoBot 集成进 Django ::

from django.conf.urls import patterns, include, url
from werobot.contrib.django import make_view
from robot import robot
from robot import myrobot

urlpatterns = patterns('',
url(r'^robot/', make_view(robot)),
url(r'^robot/', make_view(myrobot)),
)

.. module:: werobot.contrib.django
Expand All @@ -41,23 +41,23 @@ Flask

from werobot import WeRoBot

robot = WeRoBot(token='token')
myrobot = WeRoBot(token='token')


@robot.handler
@myrobot.handler
def hello(message):
return 'Hello World!'

然后, 在 Flask 项目中为 Flask 实例集成 WeRoBot ::

from flask import Flask
from robot import robot
from robot import myrobot
from werobot.contrib.flask import make_view

app = Flask(__name__)
app.add_url_rule(rule='/robot/', # WeRoBot 挂载地址
endpoint='werobot', # Flask 的 endpoint
view_func=make_view(robot),
view_func=make_view(myrobot),
methods=['GET', 'POST'])

.. module:: werobot.contrib.flask
Expand All @@ -70,9 +70,9 @@ Bottle

from werobot import WeRoBot

robot = WeRoBot(token='token')
myrobot = WeRoBot(token='token')

@robot.handler
@myrobot.handler
def hello(message):
return 'Hello World!'

Expand All @@ -82,7 +82,7 @@ Bottle
app = Bottle()
app.route('/robot', # WeRoBot 挂载地址
['GET', 'POST'],
make_view(robot))
make_view(myrobot))

.. module:: werobot.contrib.bottle
.. autofunction:: make_view
Expand All @@ -96,15 +96,15 @@ Tornado
from werobot import WeRoBot
from werobot.contrib.tornado import make_handler

robot = WeRoBot(token='token')
myrobot = WeRoBot(token='token')


@robot.handler
@myrobot.handler
def hello(message):
return 'Hello World!'

application = tornado.web.Application([
(r"/robot/", make_handler(robot)),
(r"/robot/", make_handler(myrobot)),
])

if __name__ == "__main__":
Expand Down
4 changes: 3 additions & 1 deletion docs/encryption.rst
Expand Up @@ -2,14 +2,16 @@
==========

WeRoBot 支持对消息的加解密,即微信公众号的安全模式。
在开启消息加解密功能之前,请先阅读微信官方的 `消息加解密说明 <https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1434696670>`_
为 WeRoBot 开启消息加密功能,首先需要安装 ``cryptography`` ::

pip install cryptography

之后, 你只需要将你在微信公众平台后台设置的 `EncodingAESKey` 加到 WeRoBot 的 :ref:`Config` 里面就可以了 ::
之后, 你只需要将开发者 ID(`AppID`) 和微信公众平台后台设置的 `EncodingAESKey` 加到 WeRoBot 的 :ref:`Config` 里面就可以了 ::

from werobot import WeRoBot
robot = WeRoBot()
robot.config["APP_ID"] = "Your AppID"
robot.config['ENCODING_AES_KEY'] = 'Your Encoding AES Key'

WeRoBot 之后会自动进行消息的加解密工作。

0 comments on commit ae9180a

Please sign in to comment.