ianva / vim-youdao-translater

vim的有道取词翻译插件
ianva.github.com
Other
132 stars 32 forks source link

Reduct number of times to access youdao server from N to 1. #17

Closed ketor closed 7 years ago

ketor commented 7 years ago

Original code split lines, and access youdao server 1 time per line. But it looks that youdao server has antispam strategy, too many access within a short time is blocked by youdao server.

This commit only send 1 request to youdao server for multi lines, parse the response and merge response into one string.

So now we can rarely see blocked by youdao server.

Signed-off-by: KetorD d.ketor@gmail.com

ketor commented 7 years ago

原版对输入是每一行,要发一次request给有道的服务器,根据最近几天的实测,服务器是有一些antispam策略的,短时间频繁访问无法返回结果的情况经常出现。 增加这个commit的修改后,访问有道服务器的频率降到每次都是1个查询,被服务器block的情况发生的少了许多。

{ "type": "EN2ZH_CN", "errorCode": 0, "elapsedTime": 1, "translateResult": [ [ { "src": "Vim version 7 4 is needed on your Linux server, then the steps:", "tgt": "Vim版本7 4是需要您的Linux服务器上,那么步骤:" } ], [ { "src": "", "tgt": "" } ], [ { "src": "1 You need install vimrc on a Mac/Linux with internet first", "tgt": "1你需要安装vimrc Mac / Linux与互联网" } ] ] }

根据测试发现这个接口是可以发送多行数据的,返回的结果其实是个list,把list里每一个tgt逐一取出拼接成一个完整结果即可。

ketor commented 7 years ago

Tested on my Mac, both Vim(+python) and MacVim(+python3) is OK.

Please review @ianva .

Thanks!