Skip to content

Instantly share code, notes, and snippets.

@patmaddox
Last active July 11, 2017 05:32
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 patmaddox/9d797d20193b82672270006997ba5197 to your computer and use it in GitHub Desktop.
Save patmaddox/9d797d20193b82672270006997ba5197 to your computer and use it in GitHub Desktop.
Ruby script to generate random experiment id for email list CSV files
# Generate a random experiment id for existing drip subscribers
# Import the generated output.csv file back into drip...
# Use at your own risk (but it worked for me :)
require 'csv'
input_file = ARGV[0]
column_name = ARGV[1]
max_value = ARGV[2].to_i
unless input_file && File.file?(input_file) && column_name && max_value > 0
$stderr.puts "Usage: ruby drip_exp_id.rb INPUT_FILE_NAME COLUMN_NAME MAX_VALUE"
$stderr.puts "example: ruby drip_exp_id.rb subscribers.csv experiment_id 6"
exit 1
end
records = CSV.parse File.read(input_file)
header = records.shift
$stderr.puts "error: expected column 2 to be 'email'" and exit 1 unless header[1] == "email"
CSV.open("output.csv", "wb") do |csv|
csv << ['email', column_name]
records.each {|r| csv << [r[1], rand(max_value) + 1] }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment