Skip to content

Instantly share code, notes, and snippets.

@dysbulic
Last active January 3, 2016 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dysbulic/8492588 to your computer and use it in GitHub Desktop.
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.
#!/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