Created
January 4, 2014 20:15
-
-
Save andrei512/8260130 to your computer and use it in GitHub Desktop.
dict.cc API ... ish
This file contains 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
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