Updating batch inviter
This commit is contained in:
parent
983d4e5598
commit
3d88095ba2
4 changed files with 38 additions and 35 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -19,6 +19,10 @@ vendor/bundle/*
|
||||||
config/database.yml
|
config/database.yml
|
||||||
.rvmrc_custom
|
.rvmrc_custom
|
||||||
|
|
||||||
|
#Mailing list stuff
|
||||||
|
config/email_offset
|
||||||
|
config/mailing_list.csv
|
||||||
|
|
||||||
# Generated files
|
# Generated files
|
||||||
log/*
|
log/*
|
||||||
public/stylesheets/*.css
|
public/stylesheets/*.css
|
||||||
|
|
|
||||||
|
|
@ -2,26 +2,32 @@
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
module RakeHelpers
|
module RakeHelpers
|
||||||
def process_emails(csv, num_to_process, offset, num_invites=10, test=true)
|
|
||||||
|
def load_yaml
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def process_emails(csv, num_to_process, offset, test=true)
|
||||||
if RUBY_VERSION.include? "1.8"
|
if RUBY_VERSION.include? "1.8"
|
||||||
|
|
||||||
require 'fastercsv'
|
require 'fastercsv'
|
||||||
backers = FasterCSV.read(csv)
|
backers = FasterCSV.read(csv)
|
||||||
else
|
else
|
||||||
require 'csv'
|
require 'csv'
|
||||||
backers = CSV.read(csv)
|
backers = CSV.read(csv)
|
||||||
end
|
end
|
||||||
puts "IN TEST MODE" if test
|
puts "DRY RUN" if test
|
||||||
churn_through = 0
|
churn_through = 0
|
||||||
num_to_process.times do |n|
|
num_to_process.times do |n|
|
||||||
if backers[n+offset] == nil
|
if backers[n+offset] == nil
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
churn_through = n
|
churn_through = n
|
||||||
backer_name = backers[n+offset][0].to_s.strip
|
backer_name = backers[n+offset][1].to_s.strip
|
||||||
backer_email = backers[n+offset][1].to_s.gsub('.ksr', '').strip
|
backer_email = backers[n+offset][0].to_s.strip
|
||||||
unless User.find_by_email(backer_email)
|
unless User.find_by_email(backer_email) || User.find_by_invitation_identifier(backer_email)
|
||||||
puts "sending email to: #{backer_name} #{backer_email}" unless Rails.env == 'test'
|
puts "sending email to: #{backer_name} #{backer_email}" unless Rails.env == 'test'
|
||||||
Invitation.create_invitee(:service => 'email', :identifier => backer_email, :name => backer_name, :invites => num_invites) unless test
|
Invitation.create_invitee(:service => 'email', :identifier => backer_email, :name => backer_name ) unless test
|
||||||
else
|
else
|
||||||
puts "user with the email exists: #{backer_email} , #{backer_name} " unless Rails.env == 'test'
|
puts "user with the email exists: #{backer_email} , #{backer_name} " unless Rails.env == 'test'
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,27 +8,28 @@ namespace :invites do
|
||||||
|
|
||||||
desc 'send a bunch of invites from a csv with rows of name, email'
|
desc 'send a bunch of invites from a csv with rows of name, email'
|
||||||
|
|
||||||
task :send, :filename, :number, :start do |t, args|
|
task :send, :number, :test do |t, args|
|
||||||
puts "this task assumes the first line of your csv is just titles(1 indexed)"
|
|
||||||
puts "MAKE SURE YOU HAVE RAN THIS ON THE RIGHT DB rake 'invites:send[filename, number, start] RAILS_ ENV=production'"
|
|
||||||
puts Rails.env
|
|
||||||
unless args[:filename]
|
|
||||||
raise "please give me {filename.csv} {number of people to churn}, {where to start in the file}"
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
require File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')
|
require File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')
|
||||||
|
|
||||||
filename = args[:filename]
|
filename = Rails.root + 'mailing_list.csv'
|
||||||
start = args[:start].to_i || 0
|
offset_filename = File.join(Rails.root, 'config', 'email_offset')
|
||||||
number_of_backers = args[:number] || 1000
|
number_of_backers = args[:number] ? args[:number].to_i : 1000
|
||||||
offset = 1 + start
|
|
||||||
puts "emailing #{number_of_backers.to_i} people listed in #{filename} starting at #{offset}"
|
|
||||||
|
|
||||||
finish_num = process_emails(filename, number_of_backers.to_i, offset)
|
offset = if File.exists?(offset_filename)
|
||||||
|
File.read(offset_filename).to_i
|
||||||
|
else
|
||||||
|
1
|
||||||
|
end
|
||||||
|
test = !(args[:test] == 'false')
|
||||||
|
puts "emailing #{number_of_backers} people listed in #{filename} starting at #{offset}"
|
||||||
|
|
||||||
puts "you ended on #{offset + finish_num}"
|
finish_num = process_emails(filename, number_of_backers, offset, test)
|
||||||
|
|
||||||
|
new_offset = offset + finish_num + 1
|
||||||
|
File.open(File.join(Rails.root, 'config', 'email_offset'), 'w') do |f|
|
||||||
|
f.write(new_offset)
|
||||||
|
end
|
||||||
|
puts "you ended on #{new_offset}"
|
||||||
puts "all done"
|
puts "all done"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -15,25 +15,17 @@ describe RakeHelpers do
|
||||||
end
|
end
|
||||||
it 'should send emails to each backer' do
|
it 'should send emails to each backer' do
|
||||||
Invitation.should_receive(:create_invitee).exactly(3).times
|
Invitation.should_receive(:create_invitee).exactly(3).times
|
||||||
process_emails(@csv, 100, 1, 10, false)
|
process_emails(@csv, 100, 1, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not send the email to the same email twice' do
|
it 'should not send the email to the same email twice' do
|
||||||
process_emails(@csv, 100, 1, 10, false)
|
process_emails(@csv, 100, 1, false)
|
||||||
|
|
||||||
Devise.mailer.deliveries.count.should == 3
|
Devise.mailer.deliveries.count.should == 3
|
||||||
process_emails(@csv, 100, 1, 10, false)
|
process_emails(@csv, 100, 1, false)
|
||||||
|
|
||||||
Devise.mailer.deliveries.count.should == 3
|
Devise.mailer.deliveries.count.should == 3
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should make a user with 10 invites' do
|
|
||||||
lambda {
|
|
||||||
process_emails(@csv, 1, 1, 10, false)
|
|
||||||
}.should change(User, :count).by(1)
|
|
||||||
|
|
||||||
User.last.invites.should == 10
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue