Last active
February 24, 2017 02:53
-
-
Save wlib/2bed9c685f21a5b73264518b6acf5e39 to your computer and use it in GitHub Desktop.
Duolingo translate API
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
# Duolingo's unofficial translation API | |
# Please comment or send me a message if you find more endpoint and/or info | |
require "open-uri" | |
require "json" | |
require "cgi" | |
def ask() | |
# Get languages | |
puts "* Use language codes, i.e. `en`, `de`, `ru` *" | |
print "To language > " | |
to_lang = gets.chomp | |
print "From language [en] > " | |
from_lang = gets.chomp | |
if from_lang == "" | |
from_lang = "en" | |
end | |
# Ask for input | |
print "Single word [1 - Default] | Word list [2] | Sentence [3] > " | |
input_choice = gets.to_i | |
input_type = "" | |
input = "" | |
case input_choice | |
when 2 | |
input_type = "tokens" | |
print "['Word', 'array', 'please'] > " | |
input = CGI.escape( gets.chomp ) | |
when 3 | |
input_type = "sentence" | |
print "Sentence > " | |
input = CGI.escape( gets.chomp ) | |
else | |
input_type = "token" | |
print "Word > " | |
input = CGI.escape( gets.chomp ) | |
end | |
return "https://d2.duolingo.com/api/1/dictionary/hints/#{from_lang}/#{to_lang}?#{input_type}=#{input}" | |
end | |
puts open( ask() ).read |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment