Created
March 19, 2011 01:56
-
-
Save yohfee/877141 to your computer and use it in GitHub Desktop.
/lib/earthquake/commands.rbの"init"ブロック内に追記
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
| command :zenra do |m| | |
| require 'open-uri' | |
| require 'rexml/document' | |
| sentence = m[1] | |
| appid = 'YOUR_YAHOO_APPID' | |
| position = '動詞' | |
| text = '全裸で' | |
| base_url = 'http://jlp.yahooapis.jp/MAService/V1/parse' | |
| raise 'appid is not configured.' if appid.nil? || appid.empty? | |
| req = "#{base_url}?results=ma&appid=#{appid}&sentence=#{URI.encode(sentence)}" | |
| res = open(req).read | |
| xml = REXML::Document.new(res) | |
| return sentence if xml.elements['ResultSet/ma_result/total_count'].text == '0' | |
| result = '' | |
| xml.elements.each('ResultSet/ma_result/word_list/word') do |e| | |
| result << text if e.elements['pos'].text == position | |
| result << e.elements['surface'].text | |
| end | |
| twitter.update(result) if confirm("update '#{result}'") | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment