lib/client.rb in navi_client-1.2.6 vs lib/client.rb in navi_client-1.2.7

- old
+ new

@@ -158,6 +158,26 @@ imap.disconnect @logger.info "#{$0} has ended (crowd applauds)" exit 0 end + + def create_csv(owners_resource_name) + s3_obj.bucket('navi-spark').object('key') + Email.where(owner: owners_resource_name).each do |e| + out = [] + e.topics.each do |t| + t_h = TopicHistory.where(email_id: e.id, topic_id: t.id) + score = t_h.blank? ? 0.0 : t_h.first.total_topics + out << [t.id, t.topic_name, e.id, total_topics, owners_resource_name] + end + CSV.open("#{owners_resource_name}.csv", "a+") do |csv| + out.each do |o| + csv << o + end + end + File.open("#{owners_resource_name}", 'csv') do |file| + s3_obj.put(body: file) + end + end + end end