Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'csv'
require 'net/http'
require 'json/ext'
csv_string = "Shen,Lui,sliu+cs@stelladot.com,,Yes,No,No
Shen,Lui,sliu@stelladot.com,,No,No,Yes"
out_file = File.open("users_data.txt", 'w')
CSV.parse(csv_string) do |row|
#get the data from csv
first_name = row[0]
last_name = row[1]
email = row[2]
password = (0...6).map { (65 + rand(26)).chr }.join
# password = "111111"
is_merch = row[5] == 'Yes'
is_cs = row[6] == 'Yes'
role = 'dsr'
if is_cs
role = 'cs'
elsif is_merch
role = 'merchant'
end
Whitelist.create!(first_name: first_name, last_name: last_name, email: email)
user = User.create!(
:first_name => first_name,
:last_name => last_name,
:password => password,
:email => email,
:email_confirmation => email,
:role => role,
phone_number: '0123456789',
social_security_number: '123456789',
birthday: 18.years.ago,
account_address: AccountAddress.create(address1: "117 Sherbrook Drive", address2: "Apt 3B", city: "Berkeley Heights", state: "NJ", zip_code: "07922"),
:state => "active")
out_file.puts "email: #{user.email} - DSR login:#{user.dsr_login} - Pwd:#{password}"
end
out_file.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment