Commit bd930037a987cf4d33f02691fe3422828d7e1b86

Authored by Leandro Santos
1 parent e4953200
Exists in master

adding comments job

Showing 1 changed file with 35 additions and 0 deletions   Show diff stats
lib/juventude_plugin/comments_job.rb 0 → 100644
@@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
  1 +# encoding: UTF-8
  2 +class JuventudePlugin::CommentsJob < JuventudePlugin::ReportJob
  3 +
  4 + def perform
  5 + profile = Profile.find(profile_id)
  6 + report_folder = JuventudePlugin::ReportJob.create_report_path(profile, report_path)
  7 + create_comments_report(profile, report_folder)
  8 + end
  9 +
  10 + def create_comments_report(profile, report_folder)
  11 + proposals = ProposalsDiscussionPlugin::Proposal.all
  12 + filepath = "/tmp/#{report_path}/comments.csv"
  13 + CSV.open(filepath, 'w', {:col_sep => ';', :force_quotes => true} ) do |csv|
  14 + csv << ['Id Comentário','Id Proposta','Data', 'Título', 'Conteúdo','Link']
  15 + proposals.map do |proposal|
  16 + count = 0
  17 + amount_proposal_comments = proposal.comments.count
  18 + proposal.comments.map do |comment|
  19 + count += 1
  20 + puts "%s de %s: adicionando comentario da proposta: %s" % [count, amount_proposal_comments, proposal.id ]
  21 + info = []
  22 + info.push(comment.id)
  23 + info.push(proposal.id)
  24 + info.push(comment.created_at.strftime("%d/%m/%y %H:%M"))
  25 + info.push(comment.title)
  26 + info.push(comment.body)
  27 + info.push("http://juventude.gov.br/#{proposal.profile.identifier}/#{proposal.path}#comment-#{comment.id}")
  28 + csv << info
  29 + end
  30 + end
  31 + end
  32 + upload_file(compress_files('comments', 'comments.csv'), profile, report_folder)
  33 + end
  34 +
  35 +end