Created
June 12, 2018 21:57
-
-
Save CodingFu/f6543d4b5d0ffeb1b7961650ce5f02df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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