Skip to content

Instantly share code, notes, and snippets.

@peerau

peerau/google.rb Secret

Created May 24, 2012 08:15
Show Gist options
  • Save peerau/eabab84e4e02b67cea08 to your computer and use it in GitHub Desktop.
Save peerau/eabab84e4e02b67cea08 to your computer and use it in GitHub Desktop.
rachael plugin
# encoding: utf-8
class Google
include Cinch::Plugin
match /g(?:oogle)? (.+)/i
def execute(m, query)
return unless ignore_nick(m.user.nick).nil?
begin
@bitly = Bitly.new($BITLYUSER, $BITLYAPI)
@url = "http://www.google.com/search?q=#{CGI.escape(query)}"
@res = Nokogiri::HTML(open(@url)).at("h3.r")
def search(number)
title = @res.text
link = @res.at('a')[:href]
link = @bitly.shorten("http://www.google.com#{link}")
desc = @res.at("./following::div").children.first.text
"Google 2| \"%s\" %s… 2| %s" % [title, desc[0..100], link.shorten]
end
more = @bitly.shorten("http://www.google.com/search?q=#{URI.escape(query)}")
m.reply search(1)
m.reply "Google 2| More results #{more.shorten}"
rescue
p $!; puts $@.join("\n")
m.reply "Google 2| Error"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment