Commit 14cab1934b678869e16e9e0943d0e7a93baaba21
1 parent
f15d5721
Exists in
master
updating scritps reports
Showing
3 changed files
with
23 additions
and
38 deletions
Show diff stats
controllers/myprofile/dialoga_plugin_myprofile_controller.rb
| 1 | class DialogaPluginMyprofileController < MyProfileController | 1 | class DialogaPluginMyprofileController < MyProfileController |
| 2 | 2 | ||
| 3 | -# before_filter :check_permission | ||
| 4 | -# protect 'edit_profile', :profile, :only => [:set_home_page] | ||
| 5 | - | 3 | + protect 'perform_task', :profile |
| 6 | 4 | ||
| 7 | def send_report | 5 | def send_report |
| 8 | -# Dir | ||
| 9 | - path = File.join(Rails.root, 'script','sent_proposal_report') | ||
| 10 | - out = IO.popen(path) | ||
| 11 | - raise out.readlines.inspect | ||
| 12 | -#profile.name | ||
| 13 | -#render :text => 'bli' | ||
| 14 | -# report = params[:report] || | ||
| 15 | -# @article.comment_paragraph_plugin_activate = !@article.comment_paragraph_plugin_activate | ||
| 16 | -# @article.save! | ||
| 17 | -# redirect_to @article.view_url | 6 | + path = File.join(Rails.root,'plugins','dialoga','script') |
| 7 | + scripts = ['sent_event_report', 'sent_proposal_report'] | ||
| 8 | + scripts.map do |script| | ||
| 9 | + cmd = File.join(path,script) + ' ' + current_person.email.to_s | ||
| 10 | + fork {IO.popen(cmd).read} | ||
| 11 | + end | ||
| 12 | + flash[:notice] = _("The report wil be sent to email #{current_person.email}") | ||
| 13 | + redirect_to :back | ||
| 18 | end | 14 | end |
| 19 | 15 | ||
| 20 | - protected | ||
| 21 | - | ||
| 22 | -# def check_permission | ||
| 23 | -# @article = profile.articles.find(params[:id]) | ||
| 24 | -# render_access_denied unless @article.comment_paragraph_plugin_enabled? && @article.allow_edit?(user) | ||
| 25 | -# end | ||
| 26 | - | ||
| 27 | end | 16 | end |
script/sent_event_report
| 1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby |
| 2 | require_relative '../../../config/environment' | 2 | require_relative '../../../config/environment' |
| 3 | -require 'net/smtp' | ||
| 4 | 3 | ||
| 5 | puts 'Iniciando script' | 4 | puts 'Iniciando script' |
| 6 | 5 | ||
| 7 | -file = File.open('event.csv', 'w+') | 6 | +file = File.open(File.join(Rails.root,'event.csv'), 'w+') |
| 8 | 7 | ||
| 9 | events = Event.all | 8 | events = Event.all |
| 10 | events.map do |event| | 9 | events.map do |event| |
script/sent_proposal_report
| 1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby |
| 2 | require_relative '../../../config/environment' | 2 | require_relative '../../../config/environment' |
| 3 | -require 'net/smtp' | ||
| 4 | 3 | ||
| 5 | -mails = ['leandronunes@gmail.com', 'leandro.santos@serpro.gov.br'] | 4 | +emails = ['leandronunes@gmail.com', 'leandro.santos@serpro.gov.br'] + ARGV |
| 5 | +emails.uniq! | ||
| 6 | 6 | ||
| 7 | puts 'Iniciando script' | 7 | puts 'Iniciando script' |
| 8 | 8 | ||
| 9 | -file = File.open('data.csv', 'w+') | 9 | +file = File.open(File.join(Rails.root,'data.csv'), 'w+') |
| 10 | 10 | ||
| 11 | -#articles = ProposalsDiscussionPlugin::Proposal.all | ||
| 12 | tasks = ProposalsDiscussionPlugin::ProposalTask.all | 11 | tasks = ProposalsDiscussionPlugin::ProposalTask.all |
| 13 | count = 0 | 12 | count = 0 |
| 14 | header = "'Origem';'Status';'Criada em';'Moderado por';'Data de Moderado';'Validado por';'Data de Validado';'Autor';'Proposta'\n" | 13 | header = "'Origem';'Status';'Criada em';'Moderado por';'Data de Moderado';'Validado por';'Data de Validado';'Autor';'Proposta'\n" |
| @@ -39,17 +38,15 @@ end | @@ -39,17 +38,15 @@ end | ||
| 39 | 38 | ||
| 40 | file.close | 39 | file.close |
| 41 | 40 | ||
| 41 | +ActionMailer::Base.logger = Logger.new(STDOUT) | ||
| 42 | +class Sender < ActionMailer::Base | ||
| 43 | + def send_report(to, from) | ||
| 44 | + attachments["eventos.csv"] = File.read("#{Rails.root}/event.csv") | ||
| 45 | + attachments["propostas.csv"] = File.read("#{Rails.root}/data.csv") | ||
| 46 | + mail to: to, from: from, | ||
| 47 | + subject: "Relatorio do Dialoga", body: "Segue em anexo os relatorios do Dialoga" | ||
| 48 | + end | ||
| 42 | 49 | ||
| 43 | - | ||
| 44 | -message = <<MESSAGE_END | ||
| 45 | -From: Relatorio Dialoga <relatorio@dialoga.gov.br> | ||
| 46 | -To: Leandro <leandronunes@gmail.com> | ||
| 47 | -Subject: Relatorio do Dialoga | ||
| 48 | - | ||
| 49 | -Segue em anexo o relatorio do Dialoga. | ||
| 50 | -MESSAGE_END | ||
| 51 | - | ||
| 52 | -Net::SMTP.start('localhost') do |smtp| | ||
| 53 | - smtp.send_message message, 'leandronunes@gmail.com', | ||
| 54 | - 'leandro.santos@serpro.gov.br' | ||
| 55 | end | 50 | end |
| 51 | + | ||
| 52 | +Sender.send_report(emails, 'dialoga@dialoga.gov.br').deliver |