class DisavowTool::ImportedLinks
Public Class Methods
new(import_file=nil)
click to toggle source
Calls superclass method
# File lib/disavow_tool/imported_links.rb, line 11 def initialize(import_file=nil) @menu_options = {whitelist_domain: "W", whitelist_url: "w", whitelist_all_urls: "a", disavow_domain: "D", disavow_url: "d", open_in_browser: "o", exit: "."} super(OPTIONS.import_files) end
Public Instance Methods
add_url_message(url)
click to toggle source
# File lib/disavow_tool/imported_links.rb, line 83 def add_url_message(url); "+++ Inserting #{url} in Imported list" end
analyse(disavowed, white_list)
click to toggle source
# File lib/disavow_tool/imported_links.rb, line 25 def analyse(disavowed, white_list) "Ready to delete analize #{@list.count} remaining links" @list.each do |url| puts "#{"*"*100}\n*" puts "* Analysing url: #{url.on_green}" if OPTIONS.network_requests print "* "+ "Obtaining website's title...\r".red.blink puts "* Website title: #{website_title(url)}".ljust(100) end puts "* URls with this same domain: #{urls_with_same_domain(url)}" puts "*\n#{"*"*100}" loop do puts menu() input = $stdin.getch case input when @menu_options[:whitelist_url] raise "Command run with no whitelist option" if OPTIONS.whitelist == false white_list.add_url url self.delete_url url when @menu_options[:whitelist_domain] raise "Command run with no whitelist option" if OPTIONS.whitelist == false domain = white_list.add_domain_from_url(url) self.delete_url url puts "Attempting to remove URLs with the domain #{domain} from imported links to stop anaylsing" self.delete_urls_if_domains(domain) when @menu_options[:whitelist_all_urls] white_list.add_urls_with_same_domain_as url, self when @menu_options[:disavow_domain] domain = disavowed.add_domain_from_url(url) self.delete_url url puts "Attempting to remove URLs with the domain #{domain} from imported links to stop anaylsing" self.delete_urls_if_domains(domain) when @menu_options[:disavow_url] disavowed.add_url(url) self.delete_url url when @menu_options[:open_in_browser] open_browser(url) when @menu_options[:exit] exit else puts "Incorrect option selected" end next if input == @menu_options[:open_in_browser] break if @menu_options.value?(input) unless input == @menu_options[:open_in_browser] end puts "\n\n#{@list.count} Remaining links to analize".blue end end
clean_line!(link)
click to toggle source
# File lib/disavow_tool/imported_links.rb, line 92 def clean_line!(link) link.gsub!(/\"/, '') # cleaning some bad links end
delete_url_message(url)
click to toggle source
# File lib/disavow_tool/imported_links.rb, line 84 def delete_url_message(url); "--- Deleting #{url} from imported list" end
import_message(link)
click to toggle source
# File lib/disavow_tool/imported_links.rb, line 85 def import_message(link) "Importing #{link} into Imported links" end
mass_delete_message()
click to toggle source
# File lib/disavow_tool/imported_links.rb, line 82 def mass_delete_message; "Ready to delete the following links" end
mensaje_sumary_before_export()
click to toggle source
# File lib/disavow_tool/imported_links.rb, line 89 def mensaje_sumary_before_export; "Links pending to analyse" end
message_sumary_imported()
click to toggle source
# File lib/disavow_tool/imported_links.rb, line 88 def message_sumary_imported; "New links imported" end
open_browser(link)
click to toggle source
# File lib/disavow_tool/imported_links.rb, line 111 def open_browser(link) if Gem.win_platform? then system "start chrome #{URL.escape(link)}" else system "open -a safari #{link}" end puts "Opening #{link}...".blue return true end
remove_known_links(known_links)
click to toggle source
# File lib/disavow_tool/imported_links.rb, line 17 def remove_known_links(known_links) mass_delete_urls(known_links) end
remove_known_links_for_domain(domains)
click to toggle source
# File lib/disavow_tool/imported_links.rb, line 21 def remove_known_links_for_domain(domains) delete_urls_if_domains(domains) end
urls_with_same_domain(url)
click to toggle source
# File lib/disavow_tool/imported_links.rb, line 136 def urls_with_same_domain(url) domain = URI.parse(URI.escape(url)).host counter = 0 self.each do |link| counter += 1 if URI.parse(URI.escape(link)).host == domain end counter end
website_title(url)
click to toggle source
# File lib/disavow_tool/imported_links.rb, line 117 def website_title(url) begin Timeout::timeout(SECONDS_TITTLE_REQUEST) do page = Nokogiri::HTML(open(URI.escape(url))) return "Empty Title" if page.css("title").blank? return page.css("title")[0].text end rescue Timeout::Error => e return "Empty Title — Request Time Out: #{e}" rescue OpenURI::HTTPError => e return "Empty Title. HTTP Error: #{e}" rescue SocketError => e return "Empty Title. Can't open site: #{e}" rescue return "Empty Tittle " end end