Skip to content

Instantly share code, notes, and snippets.

@Momozono
Last active August 29, 2015 14:22
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 Momozono/2a999f37a9441661cfa8 to your computer and use it in GitHub Desktop.
Save Momozono/2a999f37a9441661cfa8 to your computer and use it in GitHub Desktop.
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
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