Last active
April 3, 2019 09:30
-
-
Save oriolgual/f2cf90dd8ab380864349f2df000370bb to your computer and use it in GitHub Desktop.
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
begin | |
require "open-uri" | |
require "nokogiri" | |
require "typhoeus" | |
rescue Exception | |
puts "Some gems are missing, run gem install nokogiri typhoeus" | |
exit(1) | |
end | |
links = %w( | |
https://github.com/decidim/decidim/pull/4574 | |
) | |
hydra = Typhoeus::Hydra.new | |
requests = links.inject({}) do |all, link| | |
request = Typhoeus::Request.new(link, followlocation: true) | |
hydra.queue(request) | |
all.update(link => request) | |
end | |
puts "Fetching links..." | |
hydra.run | |
puts "Parsing data..." | |
data = requests.inject({}) do |all, (link, request)| | |
title = Nokogiri::HTML.parse(request.response.body).title.to_s.split(" · ").first | |
title = title.split(" by ").first | |
title = title.gsub("[BACKPORT]", "") | |
title = title.gsub("[backport]", "") | |
title = title.gsub("[Backport]", "") | |
all.update(link => title) | |
end | |
content = "<html><body><table>" | |
data.each do |link, title| | |
content += "<tr><td>#{title}</td><td>#{link}</td>" | |
end | |
content += "</table><p>Copy this into a Google Spreadsheet, and then copy the cells to a Google Doc to have a nice table</p></body></html>" | |
File.write("links.html", content) | |
puts "Done, open links.html" | |
system("open links.html") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment