Skip to content

Instantly share code, notes, and snippets.

@jiahut
Last active June 29, 2019 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiahut/f5c84eeaa288aa5719b592c784f5985a to your computer and use it in GitHub Desktop.
Save jiahut/f5c84eeaa288aa5719b592c784f5985a to your computer and use it in GitHub Desktop.
two lines implement dictionary query
#!/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[]?'`
#!/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