basic batch inviter

This commit is contained in:
maxwell 2010-11-18 15:17:22 -08:00
parent 8c092649f2
commit 970d56a007
6 changed files with 66 additions and 15 deletions

View file

@ -36,7 +36,7 @@ class Invitation
def self.create_invitee(opts = {}) def self.create_invitee(opts = {})
invitee = User.find_or_initialize_with_error_by(:email, opts[:email]) invitee = User.find_or_initialize_with_error_by(:email, opts[:email])
invitee.invites = opts[:invites]
if invitee.new_record? if invitee.new_record?
invitee.errors.clear if invitee.email.try(:match, Devise.email_regexp) invitee.errors.clear if invitee.email.try(:match, Devise.email_regexp)
else else

View file

@ -0,0 +1,12 @@
%p
Today is the day that alpha invites for Diaspora are handed out.
Chances are you were one of the first to support Diaspora.
%p
We are elated to offer you a first glimpse of our Alpha release.
We know there still are bugs and missing features, but we are excited by the progress we made in these short months.
%p
We would love your feedback, as it is the users of Diaspora which should drive what it becomes.
%p
For suggestions, feature requests, or bug reports, please use the "Feedback" link found on the left side of the page.
%p
Find more details on what what we have released on our blog, http://blog.joindiaspora.com

View file

@ -0,0 +1,12 @@
%p
Today is the day that alpha invites for Diaspora are handed out.
Chances are you were one of the first to support Diaspora.
We are elated to offer you a first glimpse of our Alpha release.
We know there still are bugs and missing features, but we are excited by the progress we made in these short months.
We would love your feedback, as it is the users of Diaspora which should drive what it becomes.
For suggestions, feature requests, or bug reports, please use the "Feedback" link found on the left side of the page.
Find more details on what what we have released

View file

@ -12,6 +12,9 @@
= t('devise.mailer.welcome', :email => @resource.email) = t('devise.mailer.welcome', :email => @resource.email)
-if @invs.count > 0 -if @invs.count > 0
= render :partial => 'inviters' = render :partial => 'inviters'
-else
= render :partial => 'batch_invites'
%p= link_to t('.accept'), accept_invitation_url(@resource, :invitation_token => @resource.invitation_token), :class => "large_text" %p= link_to t('.accept'), accept_invitation_url(@resource, :invitation_token => @resource.invitation_token), :class => "large_text"
%p.small %p.small
= t('.ignore') = t('.ignore')

21
lib/rake_helpers.rb Normal file
View file

@ -0,0 +1,21 @@
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module RakeHelpers
def process_emails(csv, num_to_process, offset)
require 'fastercsv'
backers = FasterCSV.read(csv)
churn_through = 0
num_to_process.times do |n|
if backers[n+offset] == nil
break
end
churn_through = n
backer_name = backers[n+offset][0].to_s.strip
backer_email = backers[n+offset][1].to_s.gsub('.ksr', '').strip
puts "sending email to: #{backer_name} #{backer_email}"
Invitation.create_invitee(:email => backer_email, :name => backer_name, :invites => 5)
end
churn_through
end
end

View file

@ -1,31 +1,34 @@
# Copyright (c) 2010, Diaspora Inc. This file is # Copyright (c) 2010, Diaspora Inc. This file is
# 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.
require File.join(Rails.root, 'lib', 'rake_helpers')
include RakeHelpers
namespace :invites do 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
task :send, :filename, :number, :start do |t, args|
unless args[:filename] && args[:number] && args[:start] puts "this task assumes the first line of your csv is just titles(1 indexed)"
raise "please give me {filename} {number of people to churn}, {where to start in the file}" puts "MAKE SURE YOU HAVE RAN THIS ON THE RIGHT DB rake 'invites:send[filename, number, start] RAILS_ ENV=production'"
end 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.dirname(__FILE__) + '/../../config/environment' require File.dirname(__FILE__) + '/../../config/environment'
require 'fastercsv'
filename = args[:filename] filename = args[:filename]
start = args[:start].to_i || 0 start = args[:start].to_i || 0
number_of_backers = args[:number].to_i || 1000 number_of_backers = args[:number] || 1000
offset = 1 + start offset = 1 + start
puts "emailing #{number_of_backers} listed in #{filename} starting at #{start}" puts "emailing #{number_of_backers.to_i} people listed in #{filename} starting at #{offset}"
backers = FasterCSV.read("bkr.csv")
#number_of_backers.times do |n| finish_num = process_emails(filename, number_of_backers.to_i, offset)
# backer_name = backers[n+offset][0]
# backer_email = backers[n+offset][1].gsub('.ksr', '') puts "you ended on #{offset + finish_num}"
# send_email(backer_name, backer_email) puts "all done"
#end
end end
end end