Skip to content

Instantly share code, notes, and snippets.

@adamcrown
Created January 22, 2015 20:12
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 adamcrown/9107f51f24ea933c01b1 to your computer and use it in GitHub Desktop.
Save adamcrown/9107f51f24ea933c01b1 to your computer and use it in GitHub Desktop.
Add NetIDs to CSV for production center accounts
#!/usr/bin/env ruby
script_name = File.basename(__FILE__)
file_path = ARGV[0]
abort "No input CSV file provided. Example: #{script_name} ./prod_center_accounts.csv" if file_path.nil?
abort 'File must have a .csv extension' unless file_path =~ /\.csv\Z/
new_file_path = file_path.gsub(/\.csv\Z/, '_with_netids.csv')
require 'csv'
require 'biola_web_services'
BiolaWebServices.configure do |config|
[:url, :cert_path, :key_path, :key_password, :verify_ssl, :ssl_version].each do |key|
env_value = ENV["BIOLA_WS_#{key.upcase}"]
config.send(:"#{key}=", env_value)
end
end
CSV.open(new_file_path, 'w') do |csv|
CSV.foreach(file_path, headers: true) do |row|
abort %{Could not find column "ID" in #{row.headers.join(', ')}} if row.field? 'ID'
netid = BiolaWebServices.dirsvc.get_user!(id: row['ID'].to_i)['netid']
csv << (row.fields + [netid])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment