Last active
June 29, 2019 13:31
-
-
Save jiahut/f5c84eeaa288aa5719b592c784f5985a to your computer and use it in GitHub Desktop.
two lines implement dictionary query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
abort("please spectify a word") unless word = ARGV[0] | |
puts `curl -s 'http://dict-co.iciba.com/api/dictionary.php?key=79085A8D69548E2DC4CBEC053A8124FC&type=json&w=#{word}' | jq -r '.symbols[]?.parts[]?.means[]?'` | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'digest' | |
require 'securerandom' | |
abort("please spectify a word") unless query=ARGV[0] | |
md5 = Digest::MD5.new | |
API_BASE="https://fanyi-api.baidu.com/api/trans/vip/translate" | |
from="auto" | |
to="auto" | |
salt=SecureRandom.hex | |
app_id="20190629000312263" | |
secret_key=File.read("#{Dir.home}/.translate_baidu.key").strip | |
md5 << "#{app_id}#{query}#{salt}#{secret_key}" | |
sign = md5.hexdigest | |
puts `curl -s "#{API_BASE}?q=#{query}&from=#{from}&to=#{to}&appid=#{app_id}&salt=#{salt}&sign=#{sign}" | jq -r '.trans_result[]?.dst' ` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment