Skip to content

Commit 0c02bc0

Browse files
author
whyliam
committed
优化有道单词本
1 parent 0b99d0f commit 0c02bc0

File tree

8 files changed

+42
-33
lines changed

8 files changed

+42
-33
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11

22
*.pyc
3+
history.log
4+
youdao_cookie

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
### 问题
5353

54-
如果新版本有道智云遇到问题,请参见 [错误代码列表](http://ai.youdao.com/docs/doc-trans-api.s#p06)
54+
如果新版本有道智云遇到问题,请参见 [错误代码列表](http://ai.youdao.com/docs/doc-trans-api.s#p08)
5555

5656
### 演示
5757

@@ -85,9 +85,13 @@
8585

8686
#### 同步单词到有道在线单词本 - `Alt+回车`
8787

88-
![](http://oqhtscus0.bkt.clouddn.com/4ed0a90dcfbdb62ba614b9d18bc320d7.jpg)
88+
![](https://ws4.sinaimg.cn/large/006tNc79ly1g01esa4p4bj31ig0u0atl.jpg)
8989

90-
`yourname``yoursecret` 处分别填写网易云邮箱和密码,接着按 `Alt+回车` 就能将词库存进网易有道词典的单词本。
90+
分别在`username`, `password`中输入有道的用户名和密码。
91+
92+
`filepath`中输入有道单词本离线保存的位置,默认在`~/Documents`中。
93+
94+
查询单词后按 `Alt+回车` 将单词保存到有道词典的单词本,在保存失败的时候单词将保存在离线单词本中。
9195

9296
### 更多
9397

history.log

100644100755
File mode changed.

info.plist

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
<dict>
55
<key>bundleid</key>
66
<string>whyliam.workflows.youdao</string>
7-
<key>category</key>
8-
<string>Tools</string>
97
<key>connections</key>
108
<dict>
119
<key>27E60581-8105-41DD-8E29-4FE811179098</key>
@@ -331,12 +329,6 @@
331329
<false/>
332330
<key>focusedappvariablename</key>
333331
<string></string>
334-
<key>hotkey</key>
335-
<integer>0</integer>
336-
<key>hotmod</key>
337-
<integer>0</integer>
338-
<key>hotstring</key>
339-
<string></string>
340332
<key>leftcursor</key>
341333
<false/>
342334
<key>modsmode</key>
@@ -359,7 +351,7 @@
359351
<key>escaping</key>
360352
<integer>38</integer>
361353
<key>script</key>
362-
<string>/usr/bin/python saveword.py "{query}" "us" -username yourname -password yoursecret</string>
354+
<string>/usr/bin/python saveword.py "{query}"</string>
363355
<key>scriptargtype</key>
364356
<integer>0</integer>
365357
<key>scriptfile</key>
@@ -503,6 +495,12 @@
503495
</dict>
504496
<key>variables</key>
505497
<dict>
498+
<key>filepath</key>
499+
<string>~/Documents/Alfred-youdao-wordbook.xml</string>
500+
<key>password</key>
501+
<string></string>
502+
<key>username</key>
503+
<string></string>
506504
<key>youdao_key</key>
507505
<string></string>
508506
<key>youdao_keyfrom</key>
@@ -514,8 +512,10 @@
514512
</dict>
515513
<key>variablesdontexport</key>
516514
<array>
517-
<string>youdao_keyfrom</string>
518515
<string>youdao_key</string>
516+
<string>username</string>
517+
<string>password</string>
518+
<string>youdao_keyfrom</string>
519519
<string>zhiyun_id</string>
520520
<string>zhiyun_key</string>
521521
</array>

saveword.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self, username, password, localfile, word):
5050

5151
def loginToYoudao(self):
5252
self.cj.clear()
53-
first_page = self.opener.open('http://account.youdao.com/login?back_url=http://dict.youdao.com&service=dict')
53+
first_page = self.opener.open('https://account.youdao.com/login?back_url=http://dict.youdao.com&service=dict')
5454
login_data = urllib.urlencode({
5555
'app' : 'web',
5656
'tp' : 'urstoken',
@@ -65,9 +65,12 @@ def loginToYoudao(self):
6565
'savelogin' : '1',
6666
})
6767
response = self.opener.open('https://logindict.youdao.com/login/acc/login', login_data)
68-
if response.headers.get('Set-Cookie').find(self.username) > -1:
69-
self.cj.save(cookie_filename, ignore_discard=True, ignore_expires=True)
70-
return True
68+
if response.headers.get('Set-Cookie') != None:
69+
if response.headers.get('Set-Cookie').find(self.username) > -1:
70+
self.cj.save(cookie_filename, ignore_discard=True, ignore_expires=True)
71+
return True
72+
else:
73+
return False
7174
else:
7275
return False
7376

@@ -115,17 +118,21 @@ def saveLocal(self):
115118

116119
def save(self, wf):
117120
if self.syncToYoudao() or (self.loginToYoudao() and self.syncToYoudao()):
118-
wf.logger.debug('已成功保存至线上单词本')
121+
sys.stdout.write('成功保存至线上单词本')
119122
else:
120123
result = self.saveLocal()
121-
wf.logger.debug(result if result else '帐号出错,已临时保存至本地单词本')
124+
sys.stdout.write('帐号出错,临时保存至本地单词本')
122125

123126
if __name__ == '__main__':
124127
params = sys.argv[1].split('$%')
125128

126-
username = sys.argv[ sys.argv.index('-username') + 1] if '-username' in sys.argv else None
127-
password = sys.argv[ sys.argv.index('-password') + 1] if '-password' in sys.argv else None
128-
filepath = sys.argv[ sys.argv.index('-filepath') + 1] if '-filepath' in sys.argv else os.path.join(os.environ['HOME'] , 'Documents/Alfred-youdao-wordbook.xml')
129+
username = os.getenv('username', '').strip()
130+
password = os.getenv('password', '').strip()
131+
filepath = os.getenv('filepath', '').strip()
132+
if filepath is None:
133+
filepath = os.path.join(os.environ['HOME'] , 'Documents/Alfred-youdao-wordbook.xml')
134+
else:
135+
filepath = os.path.expanduser(filepath)
129136

130137
m2 = hashlib.md5()
131138
m2.update(password)
@@ -139,6 +146,6 @@ def save(self, wf):
139146
}
140147

141148
saver = SaveWord(username, password_md5 , filepath, item)
142-
wf = Workflow3()
143149

150+
wf = Workflow3()
144151
sys.exit(wf.run(saver.save))
-331 Bytes
Binary file not shown.

youdao.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,21 @@
2727
"105": "不支持的签名类型",
2828
"106": "不支持的响应类型",
2929
"107": "不支持的传输加密类型",
30-
"108": "appKey无效,注意不是应用密钥",
30+
"108": "appKey无效,注册账号, 登录后台创建应用和实例并完成绑定, 可获得应用ID和密钥等信息,其中应用ID就是appKey( 注意不是应用密钥",
3131
"109": "batchLog格式不正确",
3232
"110": "无相关服务的有效实例",
3333
"111": "开发者账号无效",
3434
"113": "q不能为空",
3535
"201": "解密失败,可能为DES,BASE64,URLDecode的错误",
3636
"202": "签名检验失败",
3737
"203": "访问IP地址不在可访问IP列表",
38-
"205": "请求的接口与应用的平台类型不一致",
38+
"205": "请求的接口与应用的平台类型不一致,如有疑问请参考[入门指南]()",
39+
"206": "因为时间戳无效导致签名校验失败",
40+
"207": "重放请求",
3941
"301": "辞典查询失败",
4042
"302": "翻译查询失败",
4143
"303": "服务端的其它异常",
42-
"401": "账户已经欠费",
44+
"401": "账户已经欠费停",
4345
"411": "访问频率受限,请稍后访问",
4446
"412": "长请求过于频繁,请稍后访问",
4547
"500": "有道翻译失败"

youdao_cookie

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
#LWP-Cookies-2.0
2-
Set-Cookie3: DICT_LOGIN="3||1532941142168"; path="/"; domain=".youdao.com"; path_spec; domain_dot; discard; version=0
3-
Set-Cookie3: DICT_PERS="v2|urstoken||DICT||web||-1||1532941142130||60.191.68.43||[email protected]||q464e40LlMReBPMzWRMT4Re4RMz5O4qS0YfPLYG64Y50qF0flY0LQ40JunLpF0fkM06F0MTS0LYERJF64zfRfUER"; path="/"; domain=".youdao.com"; path_spec; domain_dot; expires="2018-08-28 16:06:32Z"; HttpOnly=None; version=0
4-
Set-Cookie3: DICT_SESS="v2|URSM|DICT||[email protected]||urstoken||EPOLe9UqPQ4pDySIVvEqPxyAaMSkKDxQHhS9mNpM.WMBa7s5atXR4ykIuSurD1u6zsckVJu5j_nIGF973xbsOceqDl0sBrpn9VNO62I3PTLBeg4gUP00.CzTtxWUWI50WKbu1TDmFAxX5w1ZvVgQo0jSM9YSXqMeWq2_Qb6cZIS2Wab7Z_YwE73rjhAjOgWra||604800000||qLOfl5kMY5RTZhMqzh4kM0TBh4UMkLPS0UGRLOGPMzf0gzhLgzOLzGRpS0fUG0Hw4RPBRMYWhfwyRzl6LlW6LguR"; path="/"; domain=".youdao.com"; path_spec; domain_dot; discard; HttpOnly=None; version=0
5-
Set-Cookie3: DICT_UGC="376cccb99f5ca51de4bbd163657f2fcf|[email protected]"; path="/"; domain=".youdao.com"; domain_dot; discard; version=0
6-
Set-Cookie3: JSESSIONID=abcqVhyuUs361hEJyAQtw; path="/"; domain=".youdao.com"; path_spec; discard; version=0
7-
Set-Cookie3: OUTFOX_SEARCH_USER_ID="[email protected]"; path="/"; domain=".youdao.com"; domain_dot; expires="2048-07-22 08:59:02Z"; version=0
1+
#LWP-Cookies-2.0

0 commit comments

Comments
 (0)