Created
March 22, 2011 01:28
-
-
Save yohfee/880594 to your computer and use it in GitHub Desktop.
~/.earthquake/plugin/zenra.rb
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
| #coding: utf-8 | |
| require 'open-uri' | |
| require 'rexml/document' | |
| Earthquake.init do | |
| config[:zenra] = { | |
| :appid => 'YOUR_YAHOO_APPID', | |
| :position => '動詞', | |
| :text => '全裸で', | |
| :base_url => 'http://jlp.yahooapis.jp/MAService/V1/parse' | |
| } | |
| command :zenra do |m| | |
| sentence = m[1] | |
| appid = config[:zenra][:appid] | |
| position = config[:zenra][:position] | |
| text = config[:zenra][:text] | |
| base_url = config[:zenra][:base_url] | |
| 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 | |
| # output do |item| | |
| # next unless item["stream"] | |
| # if item["text"] =~ /#{config[:zenra][:text]}/i | |
| # notify "#{item["user"]["screen_name"]}: #{item["text"]}" | |
| # end | |
| # end | |
| # filter do |item| | |
| # if item["stream"] && item["text"] | |
| # item["text"] =~ /#{config[:zenra][:text]}/i | |
| # else | |
| # true | |
| # end | |
| # end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment