Skip to content

Instantly share code, notes, and snippets.

@bknowles
Forked from ThaiWood/xkcd_passphrase.rb
Last active August 29, 2015 13:58
Show Gist options
  • Save bknowles/10403834 to your computer and use it in GitHub Desktop.
Save bknowles/10403834 to your computer and use it in GitHub Desktop.
Here's my first pass at getting the code to pass all rubocop citations.
#!/usr/bin/ruby
require 'net/http'
require 'nokogiri'
require 'rss'
require 'open-uri'
google_news_query = 'http://news.google.com/news/feeds?q=apologize&output=rss'
google_news_result_url = ''
wordlist = []
open(google_news_query) do |rss|
feed = RSS::Parser.parse(rss)
item = feed.items[0]
google_news_result_url = item.link
end
doc = Nokogiri::HTML(open(google_news_result_url))
all_words = ''
doc.traverse{ |node|
if node.text? and not node.text =~ /^\s*$/
all_words << node.text
end
}
wordlist = all_words.split("\s")
wordlist.reject!(&:empty?)
wordlist.each { |word| word.gsub! /\W/, '' }
random_output = ''
random_data = open("http://www.random.org/integers/?num=4&min=0&max=#{wordlist.length}&col=1&base=10&format=plain&rnd=new") { |data|
generated_number = data.read
random_output << generated_number.chomp
}
random_numbers = random_output.split(/\s/).map(&:to_i)
puts "#{wordlist[random_numbers[0]]} #{wordlist[random_numbers[1]]} #{wordlist[random_numbers[2]]} #{wordlist[random_numbers[3]]}"
@bknowles
Copy link
Author

Hmm. Okay, this is going to take some deeper hacking to get it to work. Sigh....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment