-
-
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.
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
#!/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]]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hmm. Okay, this is going to take some deeper hacking to get it to work. Sigh....