Skip to content

Instantly share code, notes, and snippets.

@rafapolo
Created December 2, 2011 05:13
Show Gist options
  • Save rafapolo/1421872 to your computer and use it in GitHub Desktop.
Save rafapolo/1421872 to your computer and use it in GitHub Desktop.
A partir de um link, navega aleatóriamente entre os outros links interessantes da Wikipédia.
require 'open-uri'
def html(wiki)
open("http://en.wikipedia.org/wiki/#{wiki}", 'User-Agent' => 'bot').read
end
def links(html)
html.scan(/<a href=\"\/wiki\/.+\" title=\"(\w+)\">/)[0].uniq
end
def go(word)
puts "Hey! Let's get something about #{word}."
while word do
if ways = links(html(word))
print "\nShould I go into "
ways.each {|way| print "#{way}, "}
puts "or maybe just relax?" # random
random = ways[rand(ways.size)]
puts "#{random} sound good, come on..."
word = random
else
puts "Opz! No more ways over here."
end
end
puts "..."
end
go("Ocupation")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment