Commit 2ac0a19bbfa5aa5728d23f925f57f7129cb37e9c
1 parent
c11ebee2
Exists in
master
put the report to generate noosfero files
Showing
4 changed files
with
45 additions
and
32 deletions
Show diff stats
controllers/myprofile/dialoga_plugin_myprofile_controller.rb
@@ -4,7 +4,7 @@ class DialogaPluginMyprofileController < MyProfileController | @@ -4,7 +4,7 @@ class DialogaPluginMyprofileController < MyProfileController | ||
4 | 4 | ||
5 | def send_report | 5 | def send_report |
6 | path = File.join(Rails.root,'plugins','dialoga','script') | 6 | path = File.join(Rails.root,'plugins','dialoga','script') |
7 | - scripts = ['sent_event_report', 'sent_proposal_report'] | 7 | + scripts = ['sent_event_report', 'sent_ranking', 'sent_proposal_report'] |
8 | scripts.map do |script| | 8 | scripts.map do |script| |
9 | cmd = File.join(path,script) + ' ' + current_person.email.to_s | 9 | cmd = File.join(path,script) + ' ' + current_person.email.to_s |
10 | fork {IO.popen(cmd).read} | 10 | fork {IO.popen(cmd).read} |
script/sent_event_report
1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby |
2 | # encoding: UTF-8 | 2 | # encoding: UTF-8 |
3 | -require_relative '../../../config/environment' | 3 | +include ActionDispatch::TestProcess |
4 | 4 | ||
5 | puts 'Iniciando script eventos' | 5 | puts 'Iniciando script eventos' |
6 | 6 | ||
7 | -directory = File.join(Rails.root,'data') | ||
8 | -Dir.mkdir(directory) unless File.exists?(directory) | 7 | +filebasepath = '/tmp/' |
9 | 8 | ||
10 | -file = File.open(File.join(directory,'event.csv'), 'w+') | 9 | +dialoga = Community['dialoga'] |
10 | +root_report_folder = dialoga.folders.where(:slug => 'relatorios').first | ||
11 | +root_report_folder ||= Folder.create!(:profile => dialoga, :name => 'Relatorios') | ||
12 | + | ||
13 | +report_folder = Folder.find_by_slug(DateTime.now.strftime('%Y-%m-%d')) | ||
14 | +report_folder ||= Folder.create!(:profile => dialoga, :name => DateTime.now.strftime('%Y-%m-%d'), :parent => root_report_folder) | ||
11 | 15 | ||
12 | events = Event.all | 16 | events = Event.all |
13 | events.map do |event| | 17 | events.map do |event| |
18 | + filepath = filebasepath + DateTime.now.strftime('%Y-%m-%d-%H-%m-%S') + '-' + event.slug | ||
19 | + file = File.open(File.join(filepath), 'w+') | ||
14 | file.write(event.name+ "\n") | 20 | file.write(event.name+ "\n") |
15 | header = "'Nome';'Email'\n" | 21 | header = "'Nome';'Email'\n" |
16 | file.write(header) | 22 | file.write(header) |
@@ -24,7 +30,8 @@ events.map do |event| | @@ -24,7 +30,8 @@ events.map do |event| | ||
24 | file.write(info.map{|i| "'" + i.to_s + "'"}.join(";")) | 30 | file.write(info.map{|i| "'" + i.to_s + "'"}.join(";")) |
25 | file.write("\n") | 31 | file.write("\n") |
26 | end | 32 | end |
33 | + file.close | ||
34 | + uploaded_file = UploadedFile.new(:uploaded_data => fixture_file_upload(filepath, 'text/csv'), :profile => dialoga, :parent => report_folder) | ||
35 | + uploaded_file.save | ||
27 | end | 36 | end |
28 | 37 | ||
29 | -file.close | ||
30 | - |
script/sent_proposal_report
1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby |
2 | # encoding: UTF-8 | 2 | # encoding: UTF-8 |
3 | -require_relative '../../../config/environment' | 3 | +include ActionDispatch::TestProcess |
4 | 4 | ||
5 | -directory = File.join(Rails.root,'data') | ||
6 | -Dir.mkdir(directory) unless File.exists?(directory) | 5 | +puts 'Iniciando script propostas' |
7 | 6 | ||
8 | -emails = ['leandronunes@gmail.com', 'leandro.santos@serpro.gov.br'] + ARGV | ||
9 | -emails.uniq! | 7 | +filebasepath = '/tmp/' |
8 | + | ||
9 | +dialoga = Community['dialoga'] | ||
10 | +root_report_folder = dialoga.folders.where(:slug => 'relatorios').first | ||
11 | +root_report_folder ||= Folder.create!(:profile => dialoga, :name => 'Relatorios') | ||
12 | + | ||
13 | +report_folder = Folder.find_by_slug(DateTime.now.strftime('%Y-%m-%d')) | ||
14 | + | ||
15 | +report_folder ||= Folder.create!(:profile => dialoga, :name => DateTime.now.strftime('%Y-%m-%d'), :parent => root_report_folder) | ||
10 | 16 | ||
11 | -puts 'Iniciando script propostas' | ||
12 | 17 | ||
13 | -file = File.open(File.join(directory,'data.csv'), 'w+') | 18 | + |
19 | +filepath = filebasepath + DateTime.now.strftime('%Y-%m-%d-%H-%m-%S') + '-' + 'propostas.csv' | ||
20 | +file = File.open(filepath, 'w+') | ||
14 | 21 | ||
15 | tasks = ProposalsDiscussionPlugin::ProposalTask.all | 22 | tasks = ProposalsDiscussionPlugin::ProposalTask.all |
16 | count = 0 | 23 | count = 0 |
@@ -42,16 +49,5 @@ end | @@ -42,16 +49,5 @@ end | ||
42 | 49 | ||
43 | file.close | 50 | file.close |
44 | 51 | ||
45 | -ActionMailer::Base.logger = Logger.new(STDOUT) | ||
46 | -class Sender < ActionMailer::Base | ||
47 | - def send_report(to, from) | ||
48 | - directory = File.join(Rails.root,'data') | ||
49 | - attachments["eventos.csv"] = File.read("#{directory}/event.csv") | ||
50 | - attachments["propostas.csv"] = File.read("#{directory}/data.csv") | ||
51 | - mail to: to, from: from, | ||
52 | - subject: "Relatorio do Dialoga", body: "Segue em anexo os relatorios do Dialoga" | ||
53 | - end | ||
54 | - | ||
55 | -end | ||
56 | - | ||
57 | -Sender.send_report(emails, 'dialoga@dialoga.gov.br').deliver | 52 | +uploaded_file = UploadedFile.new(:uploaded_data => fixture_file_upload(filepath, 'text/csv'), :profile => dialoga, :parent => report_folder) |
53 | +uploaded_file.save |
script/sent_ranking
1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby |
2 | # encoding: UTF-8 | 2 | # encoding: UTF-8 |
3 | - | ||
4 | -require_relative '../../../config/environment' | 3 | +include ActionDispatch::TestProcess |
4 | +require 'csv' | ||
5 | 5 | ||
6 | puts 'Iniciando script ranking' | 6 | puts 'Iniciando script ranking' |
7 | 7 | ||
8 | -directory = File.join(Rails.root,'data') | ||
9 | -Dir.mkdir(directory) unless File.exists?(directory) | 8 | +filebasepath = '/tmp/' |
9 | + | ||
10 | +dialoga = Community['dialoga'] | ||
11 | +root_report_folder = dialoga.folders.where(:slug => 'relatorios').first | ||
12 | +root_report_folder ||= Folder.create!(:profile => dialoga, :name => 'Relatorios') | ||
13 | + | ||
14 | +report_folder = Folder.find_by_slug(DateTime.now.strftime('%Y-%m-%d')) | ||
15 | + | ||
16 | +report_folder ||= Folder.create!(:profile => dialoga, :name => DateTime.now.strftime('%Y-%m-%d'), :parent => root_report_folder) | ||
10 | 17 | ||
11 | discussion = ProposalsDiscussionPlugin::Discussion.first | 18 | discussion = ProposalsDiscussionPlugin::Discussion.first |
12 | 19 | ||
@@ -14,8 +21,11 @@ articles = discussion.topics | @@ -14,8 +21,11 @@ articles = discussion.topics | ||
14 | articles.each do |article| | 21 | articles.each do |article| |
15 | puts "#{article.slug}" | 22 | puts "#{article.slug}" |
16 | ranking = article.ranking | 23 | ranking = article.ranking |
17 | - CSV.open(File.join(Rails.root,'data',"ranking_#{article.slug}.csv"), 'w' ) do |csv| | 24 | + filepath = filebasepath + DateTime.now.strftime('%Y-%m-%d-%H-%m-%S') + '-' + "ranking_#{article.slug}.csv" |
25 | + CSV.open(filepath, 'w' ) do |csv| | ||
18 | csv << ['Posição', 'Id', 'Proposta', 'Positivo', 'Negativo', 'Exibições', 'Valor'] | 26 | csv << ['Posição', 'Id', 'Proposta', 'Positivo', 'Negativo', 'Exibições', 'Valor'] |
19 | ranking.each_with_index {|r, i| csv << [i+1, r.values].flatten} | 27 | ranking.each_with_index {|r, i| csv << [i+1, r.values].flatten} |
20 | end | 28 | end |
29 | + uploaded_file = UploadedFile.new(:uploaded_data => fixture_file_upload(filepath, 'text/csv'), :profile => dialoga, :parent => report_folder) | ||
30 | + uploaded_file.save | ||
21 | end | 31 | end |