Last active
March 17, 2016 19:26
-
-
Save 3zcurdia/489169fc0eea2300f214 to your computer and use it in GitHub Desktop.
Spider for missing translations
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
source 'https://rubygems.org' | |
ruby '2.3.0' | |
gem 'spidr' | |
gem 'colorize' |
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
GEM | |
remote: https://rubygems.org/ | |
specs: | |
colorize (0.7.7) | |
mini_portile2 (2.0.0) | |
nokogiri (1.6.7.2) | |
mini_portile2 (~> 2.0.0.rc2) | |
spidr (0.5.0) | |
nokogiri (~> 1.3) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
colorize | |
spidr | |
BUNDLED WITH | |
1.11.2 |
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
require 'spidr' | |
require 'colorize' | |
# url_map = Hash.new([]) | |
error_pages = [] | |
missing_translation_pages = [] | |
pages_count = 0 | |
host = "http://localhost:3000/" | |
token = 'b8d976df8343717018a2fd826606c4ad' | |
def page_status(page) | |
return '[OK]'.colorize(:green) if page.is_ok? | |
return '[Forbidden]'.colorize(:blue) if page.is_forbidden? | |
return '[Missing]'.colorize(:blue) if page.is_missing? | |
return '[Redirect]'.colorize(:yellow) if page.is_redirect? | |
return '[Unauthorized]'.colorize(:red) if page.is_unauthorized? | |
return "[ERROR]".colorize(:red) if page.code == 500 | |
"[#{page.code}]".colorize(:purple) | |
end | |
start = Time.now | |
spider = Spidr.site("#{host}?access_token=#{token}", ignore_links: [/assets/,/users\/sign_out/]) do |spider| | |
spider.every_page do |page| | |
pages_count += 1 | |
puts "#{page_status(page)} #{page.url}" unless page.css? || page.javascript? | |
error_pages << page.url.to_s if page.code == 500 | |
scan = page.body.scan(/translation_missing/) | |
if scan.any? | |
puts " - body has #{scan.length} translation missing" | |
missing_translation_pages << { url: page.url.to_s, translation_missing_elements: scan.length } | |
end | |
end | |
# spider.every_link do |origin, dest| | |
# url_map[dest] << origin | |
# end | |
end | |
# spider.failures.each do |url| | |
# puts "Broken link #{url} found in:" | |
# | |
# url_map[url].each { |page| puts " #{page}" } | |
# end | |
error_pages.each do |page| | |
puts page.colorize(:red) | |
end | |
missing_translation_pages.each do |page| | |
puts "#{page[:url]} has #{page.translation_missing_elements} translation missing elements" | |
end | |
puts "Elapsed time #{Time.now - start}[s]" | |
if error_pages.empty? | |
puts "Result: #{pages_count} pages with 0 errors".colorize(:green) | |
else | |
puts "Result: #{pages_count} pages with #{error_pages.count} errors".colorize(:red) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment