Skip to content

Commit

Permalink
优化有道单词本
Browse files Browse the repository at this point in the history
  • Loading branch information
whyliam committed Feb 10, 2019
1 parent 0b99d0f commit 0c02bc0
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@

*.pyc
history.log
youdao_cookie
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

### 问题

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

### 演示

Expand Down Expand Up @@ -85,9 +85,13 @@

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

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

`yourname``yoursecret` 处分别填写网易云邮箱和密码,接着按 `Alt+回车` 就能将词库存进网易有道词典的单词本。
分别在`username`, `password`中输入有道的用户名和密码。

`filepath`中输入有道单词本离线保存的位置,默认在`~/Documents`中。

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

### 更多

Expand Down
Empty file modified history.log
100644 → 100755
Empty file.
20 changes: 10 additions & 10 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<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 @@ -331,12 +329,6 @@
<false/>
<key>focusedappvariablename</key>
<string></string>
<key>hotkey</key>
<integer>0</integer>
<key>hotmod</key>
<integer>0</integer>
<key>hotstring</key>
<string></string>
<key>leftcursor</key>
<false/>
<key>modsmode</key>
Expand All @@ -359,7 +351,7 @@
<key>escaping</key>
<integer>38</integer>
<key>script</key>
<string>/usr/bin/python saveword.py "{query}" "us" -username yourname -password yoursecret</string>
<string>/usr/bin/python saveword.py "{query}"</string>
<key>scriptargtype</key>
<integer>0</integer>
<key>scriptfile</key>
Expand Down Expand Up @@ -503,6 +495,12 @@
</dict>
<key>variables</key>
<dict>
<key>filepath</key>
<string>~/Documents/Alfred-youdao-wordbook.xml</string>
<key>password</key>
<string></string>
<key>username</key>
<string></string>
<key>youdao_key</key>
<string></string>
<key>youdao_keyfrom</key>
Expand All @@ -514,8 +512,10 @@
</dict>
<key>variablesdontexport</key>
<array>
<string>youdao_keyfrom</string>
<string>youdao_key</string>
<string>username</string>
<string>password</string>
<string>youdao_keyfrom</string>
<string>zhiyun_id</string>
<string>zhiyun_key</string>
</array>
Expand Down
27 changes: 17 additions & 10 deletions saveword.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, username, password, localfile, word):

def loginToYoudao(self):
self.cj.clear()
first_page = self.opener.open('http://account.youdao.com/login?back_url=http://dict.youdao.com&service=dict')
first_page = self.opener.open('https://account.youdao.com/login?back_url=http://dict.youdao.com&service=dict')
login_data = urllib.urlencode({
'app' : 'web',
'tp' : 'urstoken',
Expand All @@ -65,9 +65,12 @@ def loginToYoudao(self):
'savelogin' : '1',
})
response = self.opener.open('https://logindict.youdao.com/login/acc/login', login_data)
if response.headers.get('Set-Cookie').find(self.username) > -1:
self.cj.save(cookie_filename, ignore_discard=True, ignore_expires=True)
return True
if response.headers.get('Set-Cookie') != None:
if response.headers.get('Set-Cookie').find(self.username) > -1:
self.cj.save(cookie_filename, ignore_discard=True, ignore_expires=True)
return True
else:
return False
else:
return False

Expand Down Expand Up @@ -115,17 +118,21 @@ def saveLocal(self):

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

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

username = sys.argv[ sys.argv.index('-username') + 1] if '-username' in sys.argv else None
password = sys.argv[ sys.argv.index('-password') + 1] if '-password' in sys.argv else None
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')
username = os.getenv('username', '').strip()
password = os.getenv('password', '').strip()
filepath = os.getenv('filepath', '').strip()
if filepath is None:
filepath = os.path.join(os.environ['HOME'] , 'Documents/Alfred-youdao-wordbook.xml')
else:
filepath = os.path.expanduser(filepath)

m2 = hashlib.md5()
m2.update(password)
Expand All @@ -139,6 +146,6 @@ def save(self, wf):
}

saver = SaveWord(username, password_md5 , filepath, item)
wf = Workflow3()

wf = Workflow3()
sys.exit(wf.run(saver.save))
Binary file modified whyliam.workflows.youdao.alfredworkflow
Binary file not shown.
8 changes: 5 additions & 3 deletions youdao.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,21 @@
"105": "不支持的签名类型",
"106": "不支持的响应类型",
"107": "不支持的传输加密类型",
"108": "appKey无效,注意不是应用密钥",
"108": "appKey无效,注册账号, 登录后台创建应用和实例并完成绑定, 可获得应用ID和密钥等信息,其中应用ID就是appKey( 注意不是应用密钥",
"109": "batchLog格式不正确",
"110": "无相关服务的有效实例",
"111": "开发者账号无效",
"113": "q不能为空",
"201": "解密失败,可能为DES,BASE64,URLDecode的错误",
"202": "签名检验失败",
"203": "访问IP地址不在可访问IP列表",
"205": "请求的接口与应用的平台类型不一致",
"205": "请求的接口与应用的平台类型不一致,如有疑问请参考[入门指南]()",
"206": "因为时间戳无效导致签名校验失败",
"207": "重放请求",
"301": "辞典查询失败",
"302": "翻译查询失败",
"303": "服务端的其它异常",
"401": "账户已经欠费",
"401": "账户已经欠费停",
"411": "访问频率受限,请稍后访问",
"412": "长请求过于频繁,请稍后访问",
"500": "有道翻译失败"
Expand Down
8 changes: 1 addition & 7 deletions youdao_cookie
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
#LWP-Cookies-2.0
Set-Cookie3: DICT_LOGIN="3||1532941142168"; path="/"; domain=".youdao.com"; path_spec; domain_dot; discard; version=0
Set-Cookie3: DICT_PERS="v2|urstoken||DICT||web||-1||1532941142130||60.191.68.43||muyy95@163.com||q464e40LlMReBPMzWRMT4Re4RMz5O4qS0YfPLYG64Y50qF0flY0LQ40JunLpF0fkM06F0MTS0LYERJF64zfRfUER"; path="/"; domain=".youdao.com"; path_spec; domain_dot; expires="2018-08-28 16:06:32Z"; HttpOnly=None; version=0
Set-Cookie3: DICT_SESS="v2|URSM|DICT||muyy95@163.com||urstoken||EPOLe9UqPQ4pDySIVvEqPxyAaMSkKDxQHhS9mNpM.WMBa7s5atXR4ykIuSurD1u6zsckVJu5j_nIGF973xbsOceqDl0sBrpn9VNO62I3PTLBeg4gUP00.CzTtxWUWI50WKbu1TDmFAxX5w1ZvVgQo0jSM9YSXqMeWq2_Qb6cZIS2Wab7Z_YwE73rjhAjOgWra||604800000||qLOfl5kMY5RTZhMqzh4kM0TBh4UMkLPS0UGRLOGPMzf0gzhLgzOLzGRpS0fUG0Hw4RPBRMYWhfwyRzl6LlW6LguR"; path="/"; domain=".youdao.com"; path_spec; domain_dot; discard; HttpOnly=None; version=0
Set-Cookie3: DICT_UGC="376cccb99f5ca51de4bbd163657f2fcf|muyy95@163.com"; path="/"; domain=".youdao.com"; domain_dot; discard; version=0
Set-Cookie3: JSESSIONID=abcqVhyuUs361hEJyAQtw; path="/"; domain=".youdao.com"; path_spec; discard; version=0
Set-Cookie3: OUTFOX_SEARCH_USER_ID="-47078315@60.191.68.43"; path="/"; domain=".youdao.com"; domain_dot; expires="2048-07-22 08:59:02Z"; version=0
#LWP-Cookies-2.0

0 comments on commit 0c02bc0

Please sign in to comment.