Permalink
Browse files

Added task for extracting emails for mailchimp

  • Loading branch information...
1 parent 2469331 commit 1a039b35c4a86b3d38b9e0560cb41a0c09917476 Andrew Nesbitt committed Nov 30, 2013
Showing with 19 additions and 0 deletions.
  1. +1 −0 Gemfile
  2. +3 −0 Gemfile.lock
  3. +15 −0 lib/tasks/emails.rake
View
@@ -23,6 +23,7 @@ gem 'anjlab-bootstrap-rails', '~> 2.3.1', :require => 'bootstrap-rails'
gem 'simple_form'
gem 'rack-google-analytics'
gem 'ffi', '1.9.0'
+gem 'csv_shaper'
group :assets do
gem 'sass-rails'
View
@@ -78,6 +78,8 @@ GEM
thor
crack (0.4.1)
safe_yaml (~> 0.9.0)
+ csv_shaper (1.0.0)
+ activesupport (>= 3.0.0)
daemons (1.1.9)
dalli (2.6.4)
database_cleaner (1.2.0)
@@ -358,6 +360,7 @@ DEPENDENCIES
chai-jquery-rails
coffee-rails
coveralls
+ csv_shaper
dalli
database_cleaner
ejs
View
@@ -2,3 +2,18 @@ desc "Send daily emails"
task :send_emails => :environment do
User.all.each {|u| u.send_notification_email rescue nil } if Time.now.utc >= Date.parse("#{CURRENT_YEAR}-12-01") && Time.now.utc < Date.parse("#{CURRENT_YEAR}-12-25")
end
+
+desc "export emails for mailchimp"
+task :export_emails => :environment do
+ users = User.where('email is not null').reject{|u| u.email.blank?}
+
+ csv_string = CsvShaper.encode do |csv|
+ csv.headers :nickname, :email
+
+ csv.rows users do |csv, user|
+ csv.cells :nickname, :email
+ end
+ end
+
+ puts csv_string
+end

0 comments on commit 1a039b3

Please sign in to comment.