Last active
January 3, 2016 16:59
-
-
Save dysbulic/8492588 to your computer and use it in GitHub Desktop.
Compares two data dumps and prints ids in one not in the other.
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
#!/usr/bin/env ruby | |
require 'json' | |
require 'spreadsheet' | |
if ARGV.length < 2 | |
puts 'Usage: compare_dumps.rb [json|xls]{2}' | |
puts 'Outputs asset_numbers present in each file not in the other' | |
throw 'Input needed' | |
end | |
ids = ARGV.map do |arg| | |
case arg.split('.')[-1] | |
when 'json' | |
dump = JSON.parse File.read(arg) | |
ids = dump.map{ |a| a['asset_number'] } | |
when 'xls' | |
ids = nil | |
Spreadsheet.open(arg) do |book| | |
ids = book.worksheet(0).map{ |row| row[0].to_i } | |
end | |
else | |
puts "Unknown Extension: #{arg}" | |
end | |
ids | |
end | |
puts "Counts:" | |
ids.each_with_index do |list, index| | |
puts " #{ARGV[index]}: #{list.count}" | |
end | |
puts "In #{ARGV[0]} and not #{ARGV[1]}:" | |
puts (ids[0] - ids[1]).join(',') | |
puts "In #{ARGV[1]} and not #{ARGV[0]}:" | |
puts (ids[1] - ids[0]).join(',') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment