Skip to content

Commit

Permalink
3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
whyliam committed Dec 7, 2019
1 parent c461cda commit d8929cd
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 30 deletions.
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# whyliam.workflows.youdao

## 有道翻译 workflow v2.2.3
## 有道翻译 workflow v3.0.0

默认快捷键 `yd`,查看翻译结果。

Expand All @@ -24,27 +24,17 @@

### 下载

[点击下载](https://github.com/whyliam/whyliam.workflows.youdao/releases/download/2.2.3/whyliam.workflows.youdao.alfredworkflow)
[点击下载](https://github.com/whyliam/whyliam.workflows.youdao/releases/download/3.0.0/whyliam.workflows.youdao.alfredworkflow)

### 安装

1\. [下载](https://github.com/whyliam/whyliam.workflows.youdao/releases)最新版本双击安装

**老版本有道**

2\. [注册](http://fanyi.youdao.com/openapi?path=data-mode)有道翻译 API

3\. 在 Alfred 的设置中填入对应的`Key``Keyfrom`

![](http://ww2.sinaimg.cn/large/006tNbRwgy1feno2vevklj31a30os0u5.jpg)

**或者 新版本有道智云**

2\. [注册](http://ai.youdao.com/appmgr.s)有道智云应用

3\. 在 Alfred 的设置中填入对应的`应用ID``应用密钥`

![](https://ws2.sinaimg.cn/large/006tKfTcgy1fiosfttuejj31kw0vb493.jpg)
![](https://tva1.sinaimg.cn/large/006tNbRwly1g9oapg37t0j31am0sgjxr.jpg)

4\. 在 Alfred 的设置中设置快捷方式键
![](http://ww2.sinaimg.cn/large/006tNbRwgy1feno6pzaxdj31a60p0jsl.jpg)
Expand Down Expand Up @@ -93,6 +83,23 @@

查询单词后按 `Alt+回车` 将单词保存到有道词典的单词本,在保存失败的时候单词将保存在离线单词本中。

### 其他配置

| 关键字 | 说明 | 默认 |
| -------------- | ---------------------- | -------------------------------------- |
| username | 有道在线单词本用户名 | |
| password | 有道在线单词本密码 | |
| filepath | 有道离线单词本保存位置 | ~/Documents/Alfred-youdao-wordbook.xml |
| youdao_key | 老版有道翻译Key | |
| youdao_keyfrom | 老版有道翻译Keyfrom | |
| zhiyun_id | 有道智云ID | |
| zhiyun_key | 有道智云Key | |

### 问题说明

1 .**macOS** catalina 需要在 系统设置-安全性与隐私-辅助功能,重新授权`Alfred 4`权限。
1 .`whyliam.workflows.youdao 3.x`仅支持`Alfred 4``Alfred 3`请使用[历史版本](https://github.com/whyliam/whyliam.workflows.youdao/releases)

### 更多

更多问题参见[Alfred 有道翻译简介](https://blog.naaln.com/2017/04/alfred-youdao-intro/)
Expand Down Expand Up @@ -120,3 +127,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

18 changes: 11 additions & 7 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<dict>
<key>bundleid</key>
<string>whyliam.workflows.youdao</string>
<key>category</key>
<string>Tools</string>
<key>connections</key>
<dict>
<key>27E60581-8105-41DD-8E29-4FE811179098</key>
Expand Down Expand Up @@ -130,7 +132,7 @@
<key>concurrently</key>
<false/>
<key>escaping</key>
<integer>35</integer>
<integer>32</integer>
<key>script</key>
<string>/usr/bin/python splitargs.py "{query}" "search"</string>
<key>scriptargtype</key>
Expand Down Expand Up @@ -196,6 +198,8 @@
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttreatemptyqueryasnil</key>
<false/>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
Expand Down Expand Up @@ -234,7 +238,7 @@
<key>uid</key>
<string>91C343E7-50D8-4B0D-9034-1C16C20DA8D4</string>
<key>version</key>
<integer>2</integer>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
Expand All @@ -251,7 +255,7 @@
<key>uid</key>
<string>DBA62127-3B78-4B80-B82B-1C6AEC393003</string>
<key>version</key>
<integer>2</integer>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
Expand Down Expand Up @@ -314,7 +318,7 @@
<key>uid</key>
<string>0907BEF4-816F-48FF-B157-03F5C2AACEAB</string>
<key>version</key>
<integer>2</integer>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
Expand Down Expand Up @@ -353,7 +357,7 @@
<key>concurrently</key>
<false/>
<key>escaping</key>
<integer>38</integer>
<integer>32</integer>
<key>script</key>
<string>/usr/bin/python saveword.py "{query}"</string>
<key>scriptargtype</key>
Expand Down Expand Up @@ -393,7 +397,7 @@
</dict>
</array>
<key>readme</key>
<string>有道翻译 Workflow v2.2.3
<string>有道翻译 Workflow v3.0.0
默认快捷键 yd, 查看翻译结果。
Expand Down Expand Up @@ -526,7 +530,7 @@
<string>zhiyun_key</string>
</array>
<key>version</key>
<string>2.2.3</string>
<string>3.0.0</string>
<key>webaddress</key>
<string>https://github.com/whyliam/whyliam.workflows.youdao</string>
</dict>
Expand Down
1 change: 1 addition & 0 deletions splitargs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import sys
import os
import ssl
from workflow import Workflow3

reload(sys)
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.3
3.0.0
Binary file modified whyliam.workflows.youdao.alfredworkflow
Binary file not shown.
41 changes: 32 additions & 9 deletions youdao.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@
1947745089, 1947745090)

ERRORCODE_DICT = {
"20": "要翻译的文本过长",
"30": "无法进行有效的翻译",
"40": "不支持的语言类型",
"50": "无效的key",
"60": "无词典结果,仅在获取词典结果生效",
"101": "缺少必填的参数,出现这个情况还可能是et的值和实际加密方式不对应",
"102": "不支持的语言类型",
"103": "翻译文本过长",
"104": "不支持的API类型",
"105": "不支持的签名类型",
"106": "不支持的响应类型",
"107": "不支持的传输加密类型",
"108": "appKey无效,注册账号, 登录后台创建应用和实例并完成绑定,可获得应用ID和密钥等信息,其中应用ID就是appKey( 注意不是应用密钥)",
"108": "appKey无效,注册账号, 登录后台创建应用和实例并完成绑定,\
可获得应用ID和密钥等信息,其中应用ID就是appKey( 注意不是应用密钥)",
"109": "batchLog格式不正确",
"110": "无相关服务的有效实例",
"111": "开发者账号无效",
Expand Down Expand Up @@ -63,12 +69,24 @@ def init_sentry():
sentry_sdk.init(
"https://[email protected]/1500348")
with sentry_sdk.configure_scope() as scope:
scope.set_tag("version", wf.version)
user_id = get_user_id()
scope.user = {"id": user_id}
scope.set_tag("version", str(wf.version))


def sentry_message(msg):
def get_user_id():
user_id = wf.stored_data('user_id')
if user_id == None:
user_id = str(uuid.uuid1())
wf.store_data('user_id', user_id)
return user_id


def sentry_message(errorCode, msg):
if os.getenv('sentry', 'False').strip():
sentry_sdk.capture_message(msg)
with sentry_sdk.configure_scope() as scope:
scope.set_tag("errorCode", errorCode)
sentry_sdk.capture_message(msg)


def get_youdao_url(query):
Expand Down Expand Up @@ -163,10 +181,13 @@ def save_history_data(query, title, arg, ICON_DEFAULT):
def get_history_data():
with open('history.log', 'r') as file:
for line in file.readlines()[-1:-10:-1]:
line = json.loads(line)
wf.add_item(
title=line['title'], subtitle=line['subtitle'],
arg=line['arg'], valid=True, icon=line['icon'])
try:
line = json.loads(line)
wf.add_item(
title=line['title'], subtitle=line['subtitle'],
arg=line['arg'], valid=True, icon=line['icon'])
except Exception as e:
pass


def is_expired():
Expand Down Expand Up @@ -285,6 +306,8 @@ def main(wf):
errorCode = str(rt.get("errorCode"))

if ERRORCODE_DICT.has_key(errorCode):
if errorCode == "500":
sentry_message(errorCode, ERRORCODE_DICT[errorCode])
arg = ['', '', '', '', 'error']
arg = '$%'.join(arg)
wf.add_item(
Expand All @@ -300,7 +323,7 @@ def main(wf):
add_web_translation(query, isEnglish, rt)

else:
sentry_message(str(rt))
sentry_message(errorCode, '有道也翻译不出来了')
title = '有道也翻译不出来了'
subtitle = '尝试一下去网站搜索'
arg = [query, ' ', ' ', ' ']
Expand Down

0 comments on commit d8929cd

Please sign in to comment.