diff --git a/lib/csv_generator.rb b/lib/csv_generator.rb new file mode 100644 index 000000000..a155a60c5 --- /dev/null +++ b/lib/csv_generator.rb @@ -0,0 +1,207 @@ +module CsvGenerator + + PATH = '/tmp/csvs' + 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') + + def self.all_active_users + file = self.filename("all_active_users") + sql = < #{(Time.now - 1.month).to_i})" + end + + def self.old_login_query + "(last_sign_in_at < #{(Time.now - 1.month).to_i})" + 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 + <