Skip to content

Instantly share code, notes, and snippets.

@pdabrowski6
Created June 18, 2018 11:38
Show Gist options
  • Save pdabrowski6/84118aab9098bd6f7aabd450bfe02b76 to your computer and use it in GitHub Desktop.
Save pdabrowski6/84118aab9098bd6f7aabd450bfe02b76 to your computer and use it in GitHub Desktop.
The Ruby Rogues podcast - Hall of Fame
data = {}
1.upto(20) do |page|
puts "page #{page}"
url = "https://devchat.tv/ruby-rogues/page/#{page}"
response = RestClient.get(url)
html = Nokogiri::HTML(response)
html.css("h3.entry-title a").map { |e| e[:href] }.each do |url|
response = RestClient.get(url)
html = Nokogiri::HTML(response)
title = html.css("h1.entry-title").text
views = html.xpath('//span[contains(@class, "td-nr-views")]').text.to_i
data[title] = views
end
end
def display_results(data)
puts "##############"
puts "## TOP 10 ##"
puts "##############"
data.sort_by { |k, v| v }.reverse.take(10).each_with_index do |e, index|
puts "#{index + 1}. #{e.first} - #{e.last} views"
end
end
display_results(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment