From 25c0c9b70ccf4c7d9950d2ec5f9f918e6540893c Mon Sep 17 00:00:00 2001 From: Joseph Pan Date: Sat, 10 Jun 2017 17:56:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0SendQR=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E5=85=81=E8=AE=B8=E5=8F=91=E9=80=81=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E4=BA=8C=E7=BB=B4=E7=A0=81=E5=88=B0=E9=82=AE?= =?UTF-8?q?=E7=AE=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/dingdangpath.py | 1 + client/plugins/SendQR.py | 47 ++++++++++++++++++++++++++++++++++++++++ tests/test_plugins.py | 10 ++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 client/plugins/SendQR.py diff --git a/client/dingdangpath.py b/client/dingdangpath.py index c9cdec7..c127d51 100755 --- a/client/dingdangpath.py +++ b/client/dingdangpath.py @@ -7,6 +7,7 @@ DATA_PATH = os.path.join(APP_PATH, "static") LIB_PATH = os.path.join(APP_PATH, "client") +TEMP_PATH = os.path.join(APP_PATH, "temp") PLUGIN_PATH = os.path.join(LIB_PATH, "plugins") CONFIG_PATH = os.path.expanduser(os.getenv diff --git a/client/plugins/SendQR.py b/client/plugins/SendQR.py new file mode 100644 index 0000000..fe42431 --- /dev/null +++ b/client/plugins/SendQR.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8-*- + +import os +import sys + +WORDS = [u"ERWEIMA"] + + +def handle(text, mic, profile, wxbot=None): + """ + Reports the current time based on the user's timezone. + + Arguments: + text -- user-input, typically transcribed speech + mic -- used to interact with the user (for both input and output) + profile -- contains information related to the user (e.g., phone + number) + wxbot -- wechat bot instance + """ + if 'wechat' not in profile or not profile['wechat']: + mic.say(u'请先在配置文件中开启微信接入功能') + return + if 'email' not in profile or ('enable' in profile['email'] + and not profile['email']): + mic.say(u'请先配置好邮箱功能') + return + sys.path.append(mic.dingdangpath.LIB_PATH) + from app_utils import emailUser + dest_file = os.path.join(mic.dingdangpath.TEMP_PATH, 'wxqr.png') + if os.path.exists(dest_file): + mic.say(u'正在发送微信登录二维码到您的邮箱') + if emailUser(profile, u"这是您的微信登录二维码", "", [dest_file]): + mic.say(u'发送成功') + else: + mic.say(u'发送失败') + else: + mic.say(u"微信接入失败") + + +def isValid(text): + """ + Returns True if input is related to the time. + + Arguments: + text -- user-input, typically transcribed speech + """ + return all(word in text for word in ["微信", "二维码"]) diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 8c1828a..e03abf8 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -2,7 +2,7 @@ # -*- coding: utf-8-*- from nose.tools import * from client import test_mic, diagnose, dingdangpath -from client.plugins import Time, Echo, Email +from client.plugins import Time, Echo, Email, SendQR DEFAULT_PROFILE = { 'prefers_email': False, @@ -52,4 +52,12 @@ def testEmail(self): inputs = [] self.runConversation(query, inputs, Gmail) + def testSendQR(self): + if 'wechat' not in self.profile or not self.profile['wechat']: + return + + query = u"发送微信二维码" + inputs = [] + self.runConversation(query, inputs, SendQR) +