Last active
August 29, 2015 14:22
-
-
Save Momozono/2a999f37a9441661cfa8 to your computer and use it in GitHub Desktop.
This file contains 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
Gem::Specification.new do |spec| | |
spec.name = "omokoro-random" | |
spec.version = "0.0.1" | |
spec.authors = ["momozono"] | |
spec.email = ["tanatana1089@gmail.com"] | |
spec.summary = "return random article of omokoro." | |
spec.files = ["omokoro-random.rb"] | |
spec.require_path = "." | |
end |
This file contains 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
module Ruboty | |
module Handlers | |
class Nfu < Base | |
on( | |
/omokoro/, | |
name: "omokoro", #メソッドが呼ばれる | |
description: "post random omokoro article" # "@ruboty help" | |
) | |
def omokoro(msg) | |
title_array = Array.new | |
opts = { :depth_limit => 0 } | |
Anemone.crawl("http://omocoro.jp/", opts) do |anemone| | |
anemone.on_every_page do |page| | |
page.doc.xpath("//*[@id='topics']/ul[@class='list-main']//ul/li[@class='content']/span[@class='title']/a").each do |node| | |
node.xpath("./text()").each do |title| | |
title_array << title.to_s | |
end | |
end | |
end | |
end | |
msg.reply(title_array[rand(7)]) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment