disavow_tool 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: af38dc15d1fd21dcab9a427645eff07ce7119266ea529d9237b9594c941e953b
4
+ data.tar.gz: ed632a61782d1e7748a8afc7b757c321a8c67cd8ecbe628954a2dc735badd041
5
+ SHA512:
6
+ metadata.gz: 96595e35e141f4a54c291708e55af3dbfa938180a659db4e5f3b4a7e0202fd5552f3aa8bac2143330dbb5e366a5c33f487efe19d4f622cc4b3de6adab3b5ee6d
7
+ data.tar.gz: 2a3a9598ebacbd53201b754f2e03b1044ad02fc3095b2574dd80659f367f295f6d53f19a58b8c6bee8255ac091630518bd934f2373499fbd0e9262da0fb6e064
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+
14
+ /exports/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.4
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in disavow_tool.gemspec
4
+ gemspec
5
+
6
+ # Specify what Ruby version is needed
7
+ ruby '2.6.0'
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ disavow_tool (0.1.0)
5
+ activesupport
6
+ colorize
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.2.3)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ colorize (0.8.1)
17
+ concurrent-ruby (1.1.5)
18
+ diff-lcs (1.3)
19
+ i18n (1.6.0)
20
+ concurrent-ruby (~> 1.0)
21
+ minitest (5.11.3)
22
+ rake (10.5.0)
23
+ rspec (3.8.0)
24
+ rspec-core (~> 3.8.0)
25
+ rspec-expectations (~> 3.8.0)
26
+ rspec-mocks (~> 3.8.0)
27
+ rspec-core (3.8.2)
28
+ rspec-support (~> 3.8.0)
29
+ rspec-expectations (3.8.4)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.8.0)
32
+ rspec-mocks (3.8.1)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.8.0)
35
+ rspec-support (3.8.2)
36
+ thread_safe (0.3.6)
37
+ tzinfo (1.2.5)
38
+ thread_safe (~> 0.1)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ bundler (~> 2.0)
45
+ disavow_tool!
46
+ rake (~> 10.0)
47
+ rspec (~> 3.0)
48
+
49
+ RUBY VERSION
50
+ ruby 2.6.0p0
51
+
52
+ BUNDLED WITH
53
+ 2.0.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Guillermo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # DisavowTool
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/disavow_tool`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'disavow_tool'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install disavow_tool
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/disavow_tool.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "disavow_tool"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,39 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "disavow_tool/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "disavow_tool"
7
+ spec.version = DisavowTool::VERSION
8
+ spec.authors = ["Maesitos"]
9
+ spec.email = ["noreply@example.com"]
10
+
11
+ spec.summary = %q{ A simple tool to create Disavow tool }
12
+ spec.description = %q{ A simple tool to create Disavow tool }
13
+ spec.homepage = "https://github.com/maesitos/disavow_tool"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/maesitos/disavow_tool"
20
+ spec.metadata["changelog_uri"] = "https://github.com/maesitos/disavow_tool"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ # Development dependencies
32
+ spec.add_development_dependency "bundler", "~> 2.0"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+
36
+ # Dependencies
37
+ spec.add_dependency "colorize"
38
+ spec.add_dependency "activesupport"
39
+ end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'disavow_tool'
3
+
4
+ DisavowTool.run
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/ruby
2
+ require 'colorize'
3
+ require 'io/console'
4
+ require_relative 'disavow_tool/config'
5
+ require_relative 'disavow_tool/version'
6
+ require_relative 'disavow_tool/command_options.rb'
7
+ require_relative 'disavow_tool/disavow_list.rb'
8
+ require_relative 'disavow_tool/white_list.rb'
9
+ require_relative 'disavow_tool/imported_links.rb'
10
+
11
+ module DisavowTool
12
+
13
+ def self.run
14
+ puts "Importing new links".blue if OPTIONS.verbose
15
+ imported_links = ImportedLinks.new
16
+
17
+ puts "Importing Disavowed links".blue if OPTIONS.verbose
18
+ disavowed = DisavowList.new
19
+
20
+ if OPTIONS.whitelist
21
+ puts "Importing Whitelist links".blue if OPTIONS.verbose
22
+ white_list = WhiteList.new
23
+ puts "Cleagning imported links already in whitelist".blue if OPTIONS.verbose
24
+ imported_links.remove_known_links(white_list)
25
+ end
26
+
27
+
28
+ puts "Cleagning imported links already in Disavow".blue if OPTIONS.verbose
29
+ imported_links.remove_known_links(disavowed.links)
30
+
31
+ puts "Cleagning imported links with a domain existingin in Disavow".blue if OPTIONS.verbose
32
+ imported_links.remove_known_links_for_domain(disavowed.domains)
33
+
34
+ imported_links.summary
35
+
36
+ imported_links.analyse(disavowed, white_list)
37
+
38
+ disavowed.summary if OPTIONS.verbose
39
+ white_list.summary if OPTIONS.verbose
40
+
41
+ puts "Exporting...".red if OPTIONS.verbose
42
+ disavowed.export
43
+ white_list.export if OPTIONS.whitelist
44
+ end
45
+
46
+ # # We'll only analyse links that are not in
47
+ # # the Whitelist nor at Disavowed
48
+ # knwon_links = (@disavowed_links + @whitelisted_links).uniq
49
+ # @imported_links.each do |imported_link|
50
+ # knwon_links.each do |knwon_link|
51
+ # if imported_link == knwon_link
52
+ # @imported_links.delete(knwon_link)
53
+ # if Parameters::OPTIONS[:verbose]
54
+ # puts "URL #{knwon_link} already in Disavowed or Whitelist".green
55
+ # puts " Remowing #{knwon_link.on_green} from imported links.".red
56
+ # end
57
+ # end
58
+ # end
59
+ # end
60
+ #
61
+ # @imported_links.each do |imported_link|
62
+ # domain2delete = @disavowed_domains.find do |disavowed_domain|
63
+ # imported_link.match(/.+#{Regexp.escape(disavowed_domain)}.+/)
64
+ # end
65
+ #
66
+ # next if domain2delete.nil?
67
+ # @disavowed_domains.delete(domain2delete) # Carefull
68
+ # if Parameters::OPTIONS[:verbose]
69
+ # puts "Found imported links with the already in Disavowed domain #{domain2delete} ".green
70
+ # end
71
+ #
72
+ # @imported_links.reject! do |candidate_to_remove|
73
+ # if candidate_to_remove.match(/.+#{Regexp.escape(domain2delete)}.+/)
74
+ # puts " Removing #{candidate_to_remove.on_yellow} from imported links.".red if Parameters::OPTIONS[:verbose]
75
+ # true
76
+ # end
77
+ # end
78
+ # end
79
+ #
80
+ # if Parameters::OPTIONS[:verbose]
81
+ # puts "\n\n*********\n* SUMARY\n*********"
82
+ # puts "Imported:"
83
+ # puts " * #{DISAVOWED_LINKS.count} disavowed links"
84
+ # puts " * #{DISAVOWED_DOMAINS.count} disavowed domains"
85
+ # puts " * #{IMPORTED_LINKS.count} links to analyse"
86
+ # puts " * #{WHITELISTED_LINKS.count} whitelisted links"
87
+ # puts "Liks Discated: #{IMPORTED_LINKS.count - @imported_links.count}"
88
+ # puts "Links Pending to be Verified: #{@imported_links.count}".green
89
+ # end
90
+ #
91
+ #
92
+ # #Reset vars
93
+ # @disavowed_links = DISAVOWED_LINKS.clone
94
+ # @disavowed_domains = DISAVOWED_DOMAINS.clone
95
+ # @whitelisted_links = WHITELISTED_LINKS.clone
96
+ #
97
+ # @imported_links.each do |link|
98
+ # puts "\n\n#{"*"*100}\n* Analysing url: #{link.on_green}\n#{"*"*100}"
99
+ # puts "[w] to send to whitelist [d] to send to Disavow as a domain [u] to send to Disavow as a URL [o] to open the URL."
100
+ # input = $stdin.getch
101
+ # if input == "o"
102
+ # if Gem.win_platform? then system "start chrome #{link}" else system "open -a safari #{link}" end
103
+ # puts "Opening #{link}...".blue
104
+ # puts "Continue with options [w], [d] or [u]"
105
+ # input = $stdin.getch
106
+ # end
107
+ # case input
108
+ # when "w"
109
+ # @whitelisted_links << link
110
+ # puts "+++ Inserting #{link.on_green} in #{"whitelist".on_green}".light_blue if Parameters::OPTIONS[:verbose]
111
+ #
112
+ # when "d"
113
+ # host_to_disavow = URI.parse(link).host
114
+ # puts "+++ Inserting #{host_to_disavow.on_yellow} in #{"disavowed Domains".on_yellow}".light_blue if Parameters::OPTIONS[:verbose]
115
+ # @disavowed_domains << host_to_disavow
116
+ #
117
+ # puts "--- Removing #{link} from pending to verify list.".red if Parameters::OPTIONS[:verbose]
118
+ # @imported_links.delete link
119
+ #
120
+ # puts "Looking for links with the domain #{host_to_disavow} in the links pending to verified...".blue
121
+ # links_without_target_domain = @imported_links.reject{|imported_link| host_to_disavow == URI.parse(imported_link).host}
122
+ # links_found = @imported_links.count - links_without_target_domain.count
123
+ #
124
+ # if(links_found > 0)
125
+ # puts "#{links_found} links pending to veryfy with the domain #{host_to_disavow}".green
126
+ # (@imported_links - links_without_target_domain).each do |link_to_remove|
127
+ # puts "--- Removing #{link_to_remove.on_yellow} from pending to verify list.".red if Parameters::OPTIONS[:verbose]
128
+ # @imported_links.delete link_to_remove
129
+ # end
130
+ # else
131
+ # puts "No links pending to verify with the domain #{host_to_disavow}".light_blue if Parameters::OPTIONS[:verbose]
132
+ # end
133
+ #
134
+ # when "u"
135
+ # @disavowed_links << link
136
+ # @imported_links.delete link
137
+ # puts "+++ Inserting #{link.on_yellow} in #{"disavowed links".on_yellow}".light_blue if Parameters::OPTIONS[:verbose]
138
+ # else raise "Invalid character."
139
+ # end
140
+ # end
141
+ #
142
+ # if Parameters::OPTIONS[:verbose]
143
+ # puts "\n\n*********\n* SUMARY\n*********"
144
+ # puts "Links added to whitelist:"
145
+ # (@whitelisted_links - WHITELISTED_LINKS).each{ |whitelisted| puts "New whitelisted #{whitelisted}".green}
146
+ #
147
+ # puts "Links added to disavow:"
148
+ # (@disavowed_links - DISAVOWED_LINKS).each{ |disavowed_link| puts "New disavowed link #{disavowed_link}".red}
149
+ #
150
+ # puts "Domain added to disavow:"
151
+ # (@disavowed_domains - DISAVOWED_DOMAINS).each{ |disavowed_domain| puts "New disavowed link #{disavowed_domain}".red}
152
+ #
153
+ # end
154
+
155
+
156
+
157
+ end
@@ -0,0 +1,63 @@
1
+ require 'optparse'
2
+ require 'ostruct'
3
+
4
+ module DisavowTool
5
+ class Commands
6
+ def self.parse_inputs
7
+ Commands.new.parse(ARGV)
8
+ end
9
+
10
+ def parse(args)
11
+ options = OpenStruct.new
12
+ options.library = []
13
+ options.whitelist = false
14
+ options.verbose = false
15
+ options.hardcore_verbose = false
16
+
17
+ opt_parser = OptionParser.new do |opts|
18
+ opts.banner = "Usage: disavow.rb [options] --disavow FILE --import file_1,file_2,file_3 [--whitelist file1,file2,file3]"
19
+ opts.separator ""
20
+ opts.separator "Requited options:"
21
+ opts.on("-d","--disavow FILE", Array, "Disavow file as exported from Google Search Console") do |file|
22
+ options.disavow_file = file
23
+ end
24
+ opts.on("-i","--import file_1,file_2", Array, "List of URLS to analyse. The file must have one URL per line") do |file|
25
+ options.import_files = file
26
+ end
27
+
28
+ opts.separator ""
29
+ opts.separator "Optional options:"
30
+ opts.on("--whitelist file1,file2,file3", Array, "Enter any number of whitelisted files",
31
+ "whitelisted files must have one URL per line") do |file|
32
+ options.whitelist = true
33
+ options.whitelist_files = file
34
+ end
35
+
36
+ opts.on("-v", "--verbose", "Vervose mode") do
37
+ options.verbose = true
38
+ end
39
+ opts.on("-V", "--hardcore-vervose", "Print out even your mama") do
40
+ options.hardcore_verbose = true
41
+ options.verbose = true # Hardcose verbose includes regular verbose
42
+ end
43
+
44
+ opts.separator ""
45
+ opts.separator "Common options:"
46
+ # No argument, shows at tail. This will print an options summary.
47
+ opts.on_tail("-h", "--help", "Show this message") do
48
+ puts opts
49
+ exit
50
+ end
51
+ opts.on_tail("--version", "Show version") do
52
+ puts VERSION
53
+ exit
54
+ end
55
+ end
56
+
57
+ opt_parser.parse!(args)
58
+ options
59
+ end
60
+ end
61
+
62
+ OPTIONS = Commands.parse_inputs
63
+ end