Skip to content

Instantly share code, notes, and snippets.

@andrei512
Created January 4, 2014 20:15
Show Gist options
  • Save andrei512/8260130 to your computer and use it in GitHub Desktop.
Save andrei512/8260130 to your computer and use it in GitHub Desktop.
dict.cc API ... ish
require 'open-uri'
require 'nokogiri'
require 'json'
def search word
open("http://www.dict.cc/?s=#{word}").read
end
keyword = ARGV.count > 0 ? ARGV.join(" ") : "stein"
page = search(keyword)
english_words = JSON.parse("[#{page.match(/^var c1Arr = new Array\((?<list>.*)\);$/)[1]}]")
german_example = JSON.parse("[#{page.match(/^var c2Arr = new Array\((?<list>.*)\);$/)[1]}]")
puts JSON.pretty_generate(Hash[english_words.zip(german_example)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment