diff --git a/README.md b/README.md
index 34a3b1c..b9cd31a 100755
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# whyliam.workflows.youdao
-## 有道翻译 workflow v2.1.0
+## 有道翻译 workflow v2.1.1
默认快捷键 `yd`,查看翻译结果。
@@ -16,11 +16,11 @@
2. 按`Control ⌃+回车` 打开有道翻译页面
3. 按`Command ⌘+回车` 直接在打出翻译结果
4. 按`Shift ⇧+回车` 直接发音
-5. 选中文字 双击`Option ⌥`进行翻译
+5. 选中文字 双击`Option ⌥`进行翻译(需要另行设置)
### 下载
-[点击下载](https://github.com/liszd/whyliam.workflows.youdao/releases/download/2.1.0/whyliam.workflows.youdao.alfredworkflow)
+[点击下载](https://github.com/liszd/whyliam.workflows.youdao/releases/download/2.1.1/whyliam.workflows.youdao.alfredworkflow)
### 安装
@@ -34,7 +34,7 @@
![](http://ww2.sinaimg.cn/large/006tNbRwgy1feno2vevklj31a30os0u5.jpg)
-**新版本有道智云**
+**或者 新版本有道智云**
2\. [注册](http://ai.youdao.com/appmgr.s)有道智云应用
@@ -45,6 +45,10 @@
4\. 在Alfred的设置中设置快捷方式键
![](http://ww2.sinaimg.cn/large/006tNbRwgy1feno6pzaxdj31a60p0jsl.jpg)
+### 问题
+
+如果新版本有道智云遇到问题,请参见 [错误代码列表](http://ai.youdao.com/docs/api.s#id6)。
+
### 演示
#### 英译中
diff --git a/info.plist b/info.plist
index 34f9332..bd88d19 100755
--- a/info.plist
+++ b/info.plist
@@ -171,6 +171,8 @@
alfredfiltersresults
+ argumenttrimmode
+ 0
argumenttype
0
escaping
@@ -324,7 +326,7 @@
readme
- 有道翻译 Workflow v2.1.0
+ 有道翻译 Workflow v2.1.1
默认快捷键 yd, 查看翻译结果。
@@ -431,7 +433,7 @@
zhiyun_key
version
- 2.1.0
+ 2.1.1
webaddress
https://github.com/liszd/whyliam.workflows.youdao
diff --git a/version b/version
index 50aea0e..7c32728 100755
--- a/version
+++ b/version
@@ -1 +1 @@
-2.1.0
\ No newline at end of file
+2.1.1
\ No newline at end of file
diff --git a/whyliam.workflows.youdao.alfredworkflow b/whyliam.workflows.youdao.alfredworkflow
index 7d7441b..2c340ac 100644
Binary files a/whyliam.workflows.youdao.alfredworkflow and b/whyliam.workflows.youdao.alfredworkflow differ
diff --git a/youdao.py b/youdao.py
index 4b35f22..e34e2a2 100755
--- a/youdao.py
+++ b/youdao.py
@@ -16,6 +16,24 @@
2002493141, 2002493142, 2002493143,
1947745089, 1947745090)
+ERRORCODE_DICT = {
+ "50": "有道翻译的API Key错误",
+ "101": "缺少必填的参数,出现这个情况还可能是et的值和实际加密方式不对应",
+ "102": "不支持的语言类型", "103": "翻译文本过长",
+ "104": "不支持的API类型", "105": "不支持的签名类型",
+ "106": "不支持的响应类型", "107": "不支持的传输加密类型",
+ "108": "appKey无效( 注意不是应用密钥)",
+ "109": "batchLog格式不正确",
+ "110": "无相关服务的有效实例",
+ "111": "开发者账号无效,可能是账号为欠费状态",
+ "201": "解密失败,可能为DES,BASE64,URLDecode的错误",
+ "202": "签名检验失败", "203": "访问IP地址不在可访问IP列表",
+ "301": "辞典查询失败", "302": "翻译查询失败",
+ "303": "服务端的其它异常",
+ "401": "账户已经欠费停",
+ "500": "有道翻译的API Key使用频率过高"
+}
+
ICON_DEFAULT = 'icon.png'
ICON_PHONETIC = 'icon_phonetic.png'
ICON_BASIC = 'icon_basic.png'
@@ -26,15 +44,16 @@
def set_youdao_url(query):
# 构建有道翻译URL
- import os, random
+ import os
+ import random
- zhiyun_id = os.getenv('zhiyun_id', '')
- zhiyun_key = os.getenv('zhiyun_key', '')
+ zhiyun_id = os.getenv('zhiyun_id', '').strip()
+ zhiyun_key = os.getenv('zhiyun_key', '').strip()
if zhiyun_id and zhiyun_key:
url = set_youdao_new_url_from(query, zhiyun_id, zhiyun_key)
else:
- youdao_keyfrom = os.getenv('youdao_keyfrom', '')
- youdao_key = os.getenv('youdao_key', '')
+ youdao_keyfrom = os.getenv('youdao_keyfrom', '').strip()
+ youdao_key = os.getenv('youdao_key', '').strip()
if not youdao_keyfrom or not youdao_key:
i = random.randrange(0, 11, 1)
youdao_keyfrom = YOUDAO_DEFAULT_KEYFROM[i]
@@ -55,7 +74,9 @@ def set_youdao_old_url_from(query, youdao_keyfrom, youdao_key):
def set_youdao_new_url_from(query, zhiyun_id, zhiyun_key):
- import urllib, hashlib, uuid
+ import urllib
+ import hashlib
+ import uuid
salt = uuid.uuid4().hex
sign = hashlib.md5(zhiyun_id + query + salt + zhiyun_key).hexdigest()
@@ -77,11 +98,11 @@ def get_web_data(query):
return rt
except:
rt = {}
- rt['errorCode'] = 500
+ rt['errorCode'] = "500"
return rt
else:
rt = {}
- rt['errorCode'] = 500
+ rt['errorCode'] = "500"
return rt
@@ -184,36 +205,17 @@ def main(wf):
wf.send_feedback()
rt = get_web_data(query)
+ errorCode = str(rt.get("errorCode"))
- if rt.get("errorCode") in (500, u'500'):
- arg = ['', '', '', '', 'error']
- arg = '$%'.join(arg)
- wf.add_item(
- title='有道翻译的API Key使用频率过高', subtitle='', arg=arg,
- valid=True, icon=ICON_ERROR)
-
- elif rt.get("errorCode") in (108, u'108'):
- arg = ['', '', '', '', 'error']
- arg = '$%'.join(arg)
- wf.add_item(
- title='appID 或者 appKey 无效', subtitle='', arg=arg,
- valid=True, icon=ICON_ERROR)
-
- elif rt.get("errorCode") in (111, u'111', 401, u'401'):
- arg = ['', '', '', '', 'error']
- arg = '$%'.join(arg)
- wf.add_item(
- title='账号为欠费状态', subtitle='', arg=arg,
- valid=True, icon=ICON_ERROR)
-
- elif rt.get("errorCode") in (50, u'50'):
+ if ERRORCODE_DICT.has_key(errorCode):
arg = ['', '', '', '', 'error']
arg = '$%'.join(arg)
wf.add_item(
- title='有道翻译的API Key错误', subtitle='', arg=arg,
+ title=errorCode+" "+ERRORCODE_DICT[errorCode],
+ subtitle='', arg=arg,
valid=True, icon=ICON_ERROR)
- elif rt.get("errorCode") in (0, u'0'):
+ elif errorCode == "0":
isEnglish = check_English(query)
get_translation(query, isEnglish, rt)
get_phonetic(query, isEnglish, rt)