Skip to content

Instantly share code, notes, and snippets.

@CodingFu
Created June 12, 2018 21:57
Show Gist options
  • Save CodingFu/f6543d4b5d0ffeb1b7961650ce5f02df to your computer and use it in GitHub Desktop.
Save CodingFu/f6543d4b5d0ffeb1b7961650ce5f02df to your computer and use it in GitHub Desktop.
namespace :actblue do
task :import_csv => :environment do
list_id = ENV['LIST_ID']
list = List.find(list_id)
puts "Importing #{list.name}"
processed = 0
csv_path = ENV['CSV_PATH']
line_count = `wc -l "#{csv_path}"`.strip.split(' ')[0].to_i
CSV.foreach(csv_path) do |row|
processed += 1
next if processed == 1
number, email = row
phone = Phone[number]
if phone
mem = list.memberships.where(phone_id: phone.id).first
if mem
mem.add_custom_data(:actblue_membership, "1")
mem.add_custom_data(:actblue_email, email)
print '.'
end
end
puts "#{processed}/#{line_count}" if processed % 100 == 0
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment