Skip to content

Instantly share code, notes, and snippets.

@nbqx
Created July 11, 2011 05:06
Show Gist options
  • Save nbqx/1075334 to your computer and use it in GitHub Desktop.
Save nbqx/1075334 to your computer and use it in GitHub Desktop.
%w(open-uri json MeCab).each{|x| require x}
Earthquake.init do
command :jap do |m|
tw = ""
txt = MeCab::Tagger.new('-O wakati').parse(m[1]).force_encoding(Encoding::UTF_8).split(" ")
txt.each do |w|
open("http://nymnym.heroku.com/word/"+URI.encode(w)) do |r|
print "."
json = JSON.parse(r.read)
if json["status"]==false
tw = tw+json["key"]
else
if json["data"]["synonym"].length==1
tw = tw+json["data"]["mean"]
else
len = json["data"]["synonym"].length
tw = tw+json["data"]["synonym"][rand(len)]
end
end
end
end
puts ""
input(":update #{tw}")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment