module CsvGenerator PATH = '/tmp/' BACKER_CSV_LOCATION = File.join('/usr/local/app/diaspora/', 'backer_list.csv') #BACKER_CSV_LOCATION = File.join('/home/ilya/workspace/diaspora/', 'backer_list.csv') WAITLIST_LOCATION = File.join(Rails.root, 'config', 'mailing_list.csv') OFFSET_LOCATION = File.join(Rails.root, 'config', 'email_offset') UNSUBSCRIBE_LOCATION = File.join(Rails.root, 'config', 'unsubscribe.csv') def self.all_active_users file = self.filename("all_active_users") sql = < SUBDATE(NOW(), INTERVAL 31 DAY))" end def self.old_login_query "(last_sign_in_at < SUBDATE(NOW(), INTERVAL 31 DAY))" end def self.never_login_query "(last_sign_in_at IS NULL)" end def self.query_string_from_array(array) array.join(", ") end # BACKER RECENT LOGIN # User.where("last_sign_in_at > ?", (Time.now - 1.month).to_i).where(:email => ["maxwell@joindiaspora.com"]).count # # "SELECT `users`.* FROM `users` WHERE `users`.`email` IN ('maxwell@joindiaspora.com') AND (last_sign_in_at > 1312663724)" # NON BACKER RECENT LOGIN # User.where("last_sign_in_at > ?", (Time.now - 1.month).to_i).where("email NOT IN (?)", 'maxwell@joindiaspora.com').to_sql # "SELECT `users`.* FROM `users` WHERE (last_sign_in_at > 1312665370) AND (email NOT IN ('maxwell@joindiaspora.com'))" # ---------------- HELPER METHODS ------------------------- def self.load_waiting_list_csv(filename) csv = filename if RUBY_VERSION.include? "1.8" require 'fastercsv' people = FasterCSV.read(csv) else require 'csv' people = CSV.read(csv) end people end def self.offset offset_filename = OFFSET_LOCATION File.read(offset_filename).to_i end def self.filename(name) "#{PATH}#{Time.now.strftime("%Y-%m-%d")}-#{name}" end def self.output_syntax filename <