Skip to content

Commit

Permalink
script to map IAIDs by CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
bkiahstroud committed Oct 4, 2024
1 parent 7cc3e25 commit 82390df
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions bin/map_iaids_by_csv.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env ruby

require 'csv'
require 'json'
require 'fileutils'
require 'pathname'

input_csv_path = Pathname.new(ARGV[0])
raise "No file found at #{input_csv_path}" unless input_csv_path.exist?

csv_raw = CSV.read(input_csv_path)
iaid_index = csv_raw[0].index('iaid')
iaids = csv_raw.map { |row| row[iaid_index].split('|') }
iaids.flatten!
iaids.uniq!
iaids -= ['iaid', ' '] # remove column header and blank values
iaids.sort!

puts "Found #{iaids.size} unique IAIDs"

h = {}
iaids.each { |iaid| h[iaid] = {} }

filename, _ext = input_csv_path.basename.to_s.split('.')
json_filename = "#{filename}IAIDs.json"
json_path = Pathname.new("tmp/#{json_filename}")
FileUtils.mkdir_p(json_path.dirname)

File.open(json_path, 'w') do |file|
file.puts JSON.pretty_generate(JSON.parse(h.to_json))
end

puts "Output: #{json_path}"

0 comments on commit 82390df

Please sign in to comment.