Last active
December 26, 2015 04:49
-
-
Save morygonzalez/7096182 to your computer and use it in GitHub Desktop.
Yet Another 俳句が読みたくなった時用 earthquake plugin
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 -*- | |
# shinudan tweet / earthquake plugin | |
# | |
# shinudan: http://shindanmaker.com/198940 | |
# | |
require 'net/http' | |
require 'nokogiri' | |
Earthquake.init do | |
command %r|^:shinudan\s*(.+)*|, :as => :shinudan do |m| | |
url = "http://shindanmaker.com/198940" | |
c = m[1].nil? ? rand(Time.now.to_i) : m[1] | |
res = Net::HTTP.post_form(URI.parse(url), { :u => c, :from => '' }) | |
html = Nokogiri::HTML(res.body) | |
text = html.css("#forcopy").text.strip.force_encoding('utf-8').gsub(/ #{url}/, '') | |
input m[1] ? "#{m[1]} ここで一句、#{text}" : "ここで一句、#{text}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment