urldiff 0.0.7
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.
- checksums.yaml +7 -0
- data/lib/urldiff.rb +114 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b7aace70021311561a07c6566249def7386ab11d
|
4
|
+
data.tar.gz: bc9fca9b56a924f1ad2979cf49a7b7cd711cf1cd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bda6df7a9d41df781bad5ea4009c06d84ba4dd2dde3856f33fb04e4907e6be9d1ee7232af83d9cd84c2cce51f3a899726a6c3b242cb11ac8acc6d74db22e3941
|
7
|
+
data.tar.gz: d5e6224947c73728f4f5633224ceaaace2da846b4baec7a3775edb2f6a9e51ce206e9d02cdc6942f29e12c2f49b20d4a2dbe41b4e2538f8a0f9cf6f9c12fedcb
|
data/lib/urldiff.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Author: Sam Mcleod
|
3
|
+
# https://github.com/sammcj/urldiff
|
4
|
+
|
5
|
+
require 'oily_png'
|
6
|
+
require 'imgkit'
|
7
|
+
require 'tempfile'
|
8
|
+
require 'optparse'
|
9
|
+
require 'csv'
|
10
|
+
require 'wkhtmltoimg_binary'
|
11
|
+
include ChunkyPNG::Color
|
12
|
+
|
13
|
+
# Take option
|
14
|
+
options = {:first_url => nil, :second_url => nil, :keep_snaps => false, :output_cvs => nil, :input_csv => nil }
|
15
|
+
|
16
|
+
optparse = OptionParser.new do|opts|
|
17
|
+
opts.banner = "Usage: urldiff.rb [options] -f URL1 -s URL2 ..."
|
18
|
+
opts.on( '-f', '--first FIRST_URL', "First URL" ) do|first_url|
|
19
|
+
options[:first_url] = first_url
|
20
|
+
end
|
21
|
+
opts.on( '-s', '--second SECOND_URL', "Second URL" ) do|second_url|
|
22
|
+
options[:second_url] = second_url
|
23
|
+
end
|
24
|
+
opts.on( '-o', '--output FILENAME', 'Generate csv (append)' ) do|output_csv|
|
25
|
+
options[:output_csv] = output_csv
|
26
|
+
end
|
27
|
+
opts.on( '-i', '--input FILENAME', 'Import csv site list' ) do|input_csv|
|
28
|
+
options[:input_csv] = input_csv
|
29
|
+
options[:site_list] = File.path(input_csv)
|
30
|
+
end
|
31
|
+
opts.on( '-h', '--help', 'Display this screen' ) do
|
32
|
+
puts opts
|
33
|
+
puts "","Example: urldiff.rb -i sites.csv -o output.csv"
|
34
|
+
exit
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
optparse.parse!
|
39
|
+
|
40
|
+
if ARGV.empty?
|
41
|
+
puts 'hint: use -h for help'
|
42
|
+
exit
|
43
|
+
end
|
44
|
+
|
45
|
+
# Read from CSV if enabled
|
46
|
+
if !options[:input_csv]
|
47
|
+
File.open("site_list.csv", "w") do |f|
|
48
|
+
f.write "#{options[:first_url]},#{options[:second_url]}\n"
|
49
|
+
end
|
50
|
+
options[:site_list] = File.path("site_list.csv")
|
51
|
+
end
|
52
|
+
|
53
|
+
CSV.foreach(options[:site_list]) do |col|
|
54
|
+
|
55
|
+
# Where col corresponds to a zero-based value/column in the csv
|
56
|
+
first_url = col[0]
|
57
|
+
second_url = col[1]
|
58
|
+
|
59
|
+
# Strip http(s):// off for filenames
|
60
|
+
stripped_first = first_url.gsub(/^https?:\/\//, '')
|
61
|
+
stripped_second = second_url.gsub(/^https?:\/\//, '')
|
62
|
+
|
63
|
+
output_diff = "DIFF-#{stripped_first}-#{stripped_second}.png"
|
64
|
+
output_change = "CHANGES-#{stripped_first}-#{stripped_second}.png"
|
65
|
+
|
66
|
+
# Render sites as PNG
|
67
|
+
puts "Rendering #{first_url} "
|
68
|
+
kit = IMGKit.new(first_url, :quality => 50)
|
69
|
+
file = kit.to_file("#{stripped_first}.png")
|
70
|
+
|
71
|
+
puts "Rendering #{second_url} "
|
72
|
+
kit = IMGKit.new(second_url, :quality => 50)
|
73
|
+
file = kit.to_file("#{stripped_second}.png")
|
74
|
+
|
75
|
+
puts "Calculating Diff... "
|
76
|
+
images = [
|
77
|
+
ChunkyPNG::Image.from_file("#{stripped_first}.png"),
|
78
|
+
ChunkyPNG::Image.from_file("#{stripped_second}.png"),
|
79
|
+
]
|
80
|
+
|
81
|
+
diff = []
|
82
|
+
|
83
|
+
# Loop over each RGB pixel and calculate the difference
|
84
|
+
images.first.height.times do |y|
|
85
|
+
images.first.row(y).each_with_index do |pixel, x|
|
86
|
+
diff << [x,y] unless pixel == images.last[x,y]
|
87
|
+
images.last[x,y] = rgb(
|
88
|
+
r(pixel) + r(images.last[x,y]) - 2 * [r(pixel), r(images.last[x,y])].min,
|
89
|
+
g(pixel) + g(images.last[x,y]) - 2 * [g(pixel), g(images.last[x,y])].min,
|
90
|
+
b(pixel) + b(images.last[x,y]) - 2 * [b(pixel), b(images.last[x,y])].min,
|
91
|
+
)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
puts "pixels (total): #{images.first.pixels.length}"
|
96
|
+
puts "pixels changed: #{diff.length}"
|
97
|
+
puts "pixels changed (%): #{(diff.length.to_f / images.first.pixels.length) * 100}%",""
|
98
|
+
|
99
|
+
x, y = diff.map{ |xy| xy[0] }, diff.map{ |xy| xy[1] }
|
100
|
+
|
101
|
+
images.last.rect(x.min, y.min, x.max, y.max, ChunkyPNG::Color.rgb(0,255,0))
|
102
|
+
|
103
|
+
puts "Generating #{output_diff}",""
|
104
|
+
images.last.save(output_diff)
|
105
|
+
|
106
|
+
# Create CSV output if enabled
|
107
|
+
if options[:output_csv]
|
108
|
+
puts "Appending output to #{options[:output_csv]}",""
|
109
|
+
File.open(options[:output_csv], "a") do |f|
|
110
|
+
f.write "#{first_url},#{second_url},#{(diff.length.to_f / images.first.pixels.length) * 100}%\n"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: urldiff
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sam McLeod
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oily_png
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: imgkit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: wkhtmltoimg_binary
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Computes and displays the visual differences between two URLs
|
56
|
+
email:
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- lib/urldiff.rb
|
62
|
+
homepage: https://github.com/sammcj/urldiff
|
63
|
+
licenses:
|
64
|
+
- GPLv2
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '2.0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.2.2
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Computes and displays the visual differences between two URLs
|
86
|
+
test_files: []
|