Skip to content

Instantly share code, notes, and snippets.

@morygonzalez
Last active December 26, 2015 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morygonzalez/7096182 to your computer and use it in GitHub Desktop.
Save morygonzalez/7096182 to your computer and use it in GitHub Desktop.
Yet Another 俳句が読みたくなった時用 earthquake plugin
#-*- 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