Skip to content

Instantly share code, notes, and snippets.

@wbingli
Last active August 29, 2015 14:27
Show Gist options
  • Save wbingli/f8c44db563e2f890d511 to your computer and use it in GitHub Desktop.
Save wbingli/f8c44db563e2f890d511 to your computer and use it in GitHub Desktop.
require 'json'
$access_token = <your own token>
def add_word(word)
puts "Checking word : #{word}"
begin
result = `curl https://api.shanbay.com/bdc/search/?word=#{word}&access_token=#{$access_token}`
result = JSON.parse(result)
word_id = result['data']['id']
word_learning_id = result['data']['learning_id']
puts " word #{word}; id : #{word_id} ; learning_id: #{word_learning_id}"
if(word_learning_id == nil)
puts "Add word #{word} into Shanbay"
result = `curl -X POST --data "id=#{word_id}" https://api.shanbay.com/bdc/learning/?access_token=#{$access_token}`
puts result
end
rescue Exception => e
puts e
end
end
File.open('words.txt','r') do | f|
f.each_line do | line|
add_word(line) unless line.strip.length < 1
sleep 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment