wip csv gen
This commit is contained in:
parent
0e7521df9f
commit
7485271573
1 changed files with 76 additions and 14 deletions
|
|
@ -1,6 +1,9 @@
|
|||
module CsvGenerator
|
||||
|
||||
PATH = '/Users/maxwell/Sites/dump'
|
||||
PATH = '/usr/local/app/diaspora'
|
||||
BACKER_CSV_LOCATION = File.join('/usr/local/app/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")
|
||||
|
|
@ -26,20 +29,61 @@ SQL
|
|||
ActiveRecord::Base.execute(sql)
|
||||
end
|
||||
|
||||
def self.waitlist
|
||||
filename = File.join(Rails.root, 'config', 'mailing_list.csv')
|
||||
|
||||
people = self.load_waiting_list_csv
|
||||
offset = self.offset
|
||||
left = people[0...offset]
|
||||
right = people[offset...people.size]
|
||||
|
||||
#reading from csv (get number of row we're on) - left
|
||||
#reading from csv (get number of row we're on) - right
|
||||
def self.backers_recent_login
|
||||
file = self.filename("v1_backers_recent_login.csv")
|
||||
sql = <<SQL
|
||||
SELECT email AS '%EMAIL%',
|
||||
coalesce( full_name, 'friend of Diaspora*') AS '%NAME%',
|
||||
invitation_token AS '%TOKEN%'
|
||||
#{self.output_syntax(file)}
|
||||
FROM `users`
|
||||
WHERE #{self.backer_email_condition}
|
||||
AND (last_sign_in_at >= #{(Time.now - 1.month).to_i})
|
||||
SQL
|
||||
end
|
||||
|
||||
def self.load_waiting_list_csv
|
||||
csv= File.join(Rails.root, 'config', 'mailing_list.csv')
|
||||
def self.backers_older_login
|
||||
file = self.filename("v1_backers_recent_login.csv")
|
||||
sql = <<SQL
|
||||
SELECT email AS '%EMAIL%',
|
||||
coalesce( full_name, 'friend of Diaspora*') AS '%NAME%',
|
||||
invitation_token AS '%TOKEN%'
|
||||
#{self.output_syntax(file)}
|
||||
FROM `users`
|
||||
WHERE #{self.backer_email_condition}
|
||||
AND (last_sign_in_at < #{(Time.now - 1.month).to_i})
|
||||
SQL
|
||||
end
|
||||
|
||||
|
||||
# ---------------- QUERY METHODS & NOTES -------------------------
|
||||
def self.backer_email_condition
|
||||
"`users`.`email` IN (#{query_string_from_array(self.backer_emails)})"
|
||||
end
|
||||
|
||||
def self.recent_login_query
|
||||
|
||||
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)
|
||||
|
|
@ -51,7 +95,7 @@ SQL
|
|||
end
|
||||
|
||||
def self.offset
|
||||
offset_filename = File.join(Rails.root, 'config', 'email_offset')
|
||||
offset_filename = OFFSET_LOCATION
|
||||
File.read(offset_filename).to_i
|
||||
end
|
||||
|
||||
|
|
@ -66,4 +110,22 @@ FIELDS TERMINATED BY '\t'
|
|||
LINES TERMINATED BY '\n'
|
||||
SQL
|
||||
end
|
||||
|
||||
def self.waitlist
|
||||
people = self.load_waiting_list_csv(WAITLIST_LOCATION)
|
||||
offset = self.offset
|
||||
left = people[0...offset]
|
||||
right = people[offset...people.size]
|
||||
|
||||
#reading from csv (get number of row we're on) - left
|
||||
#reading from csv (get number of row we're on) - right
|
||||
end
|
||||
|
||||
def self.backers
|
||||
self.load_waiting_list_csv(BACKER_CSV_LOCATION)
|
||||
end
|
||||
|
||||
def self.backer_emails
|
||||
self.backers.map{|b| b[0]}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue