From bd930037a987cf4d33f02691fe3422828d7e1b86 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Thu, 10 Sep 2015 20:29:20 -0300 Subject: [PATCH] adding comments job --- lib/juventude_plugin/comments_job.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+), 0 deletions(-) create mode 100644 lib/juventude_plugin/comments_job.rb diff --git a/lib/juventude_plugin/comments_job.rb b/lib/juventude_plugin/comments_job.rb new file mode 100644 index 0000000..52db063 --- /dev/null +++ b/lib/juventude_plugin/comments_job.rb @@ -0,0 +1,35 @@ +# encoding: UTF-8 +class JuventudePlugin::CommentsJob < JuventudePlugin::ReportJob + + def perform + profile = Profile.find(profile_id) + report_folder = JuventudePlugin::ReportJob.create_report_path(profile, report_path) + create_comments_report(profile, report_folder) + end + + def create_comments_report(profile, report_folder) + proposals = ProposalsDiscussionPlugin::Proposal.all + filepath = "/tmp/#{report_path}/comments.csv" + CSV.open(filepath, 'w', {:col_sep => ';', :force_quotes => true} ) do |csv| + csv << ['Id Comentário','Id Proposta','Data', 'Título', 'Conteúdo','Link'] + proposals.map do |proposal| + count = 0 + amount_proposal_comments = proposal.comments.count + proposal.comments.map do |comment| + count += 1 + puts "%s de %s: adicionando comentario da proposta: %s" % [count, amount_proposal_comments, proposal.id ] + info = [] + info.push(comment.id) + info.push(proposal.id) + info.push(comment.created_at.strftime("%d/%m/%y %H:%M")) + info.push(comment.title) + info.push(comment.body) + info.push("http://juventude.gov.br/#{proposal.profile.identifier}/#{proposal.path}#comment-#{comment.id}") + csv << info + end + end + end + upload_file(compress_files('comments', 'comments.csv'), profile, report_folder) + end + +end -- libgit2 0.21.2