Commit 9659411646a2de8ec50de68018bc34f44ba2d466

Authored by Francisco Marcelo de Araújo Lima Júnior
2 parents 50245b92 cb9fa174

Merge branch 'AI3074-community_dashboard' of gitlab.com:participa/noosfero into …

…AI3074-community_dashboard
plugins/community_hub/facebook_stream/f_ainda_nao_expirou.rb
@@ -1,11 +0,0 @@ @@ -1,11 +0,0 @@
1 -require 'rubygems'  
2 -require 'koala'  
3 -require 'json'  
4 -  
5 -#@graph = Koala::Facebook::API.new('CAACEdEose0cBADWfQZB39lBDksRvjeJGGrkM3dYKTrWEG3G0m8eZCpq2Vf4dNnpAeKML3yxcTmxQ4ZAJfUcNMROrWFlonrkMiPMQlKcqLxSs9GhMWmMJvjHgPrhXJFIvBLD3Mlf0BIF89SLXlNFQj56DxtKkJpzZA8gzh0HCDGqsZA0b6kgPjPqJ2UIQsBZA4ZD')  
6 -@graph = Koala::Facebook::API.new('CAAEhsewl0ZAcBAHhipXszZCURSwWLmgvceDbs9mB5baJdLriFxYMEzywmF2fvZBuThuA2Mm7QF8wPd3E6R5pVqVEnC2VhcBb4VrfAnkZC73ZC5g1NRUnKZCB2e6CaRiUBDatR2nf505PeKp7Aj5XxvTdfSqdZCsXxQFYZApPNSUUgkUWm6HwL4rp21MRJXb612sZD')  
7 -  
8 -feed = @graph.get_connections("participabr", "posts")  
9 -  
10 -feed.each {|f| p f }  
11 -next_feed = feed.next_page  
plugins/community_hub/facebook_stream/facebook_stream.rb
@@ -2,11 +2,11 @@ require 'rubygems' @@ -2,11 +2,11 @@ require 'rubygems'
2 require 'koala' 2 require 'koala'
3 require 'json' 3 require 'json'
4 4
  5 +#Aviso 12/04/2014
5 #token que só deverá expirar em 59 dias 6 #token que só deverá expirar em 59 dias
6 @graph = Koala::Facebook::API.new('CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH') 7 @graph = Koala::Facebook::API.new('CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH')
7 8
8 -#feed = @graph.get_connections("participabr", "posts")  
9 - 9 +#feed = @graph.get_connections("participabr", "posts")
10 10
11 comentariosIniciais = [] 11 comentariosIniciais = []
12 comentariosExtraidos = [] 12 comentariosExtraidos = []
@@ -14,13 +14,13 @@ comentariosNovos = [] @@ -14,13 +14,13 @@ comentariosNovos = []
14 14
15 primeiraVez = true 15 primeiraVez = true
16 16
17 -while true 17 +while true
18 18
19 - feed = @graph.get_connections("mundoreagindo", "posts") 19 + feed = @graph.get_connections("mundoreagindo", "posts")
20 20
21 array = [] 21 array = []
22 comentariosExtraidos = [] 22 comentariosExtraidos = []
23 - feed.each {|f| 23 + feed.each {|f|
24 if f['comments'] != nil && f['comments']['data'] != nil 24 if f['comments'] != nil && f['comments']['data'] != nil
25 array.push(f['comments']['data']) 25 array.push(f['comments']['data'])
26 end 26 end
@@ -35,7 +35,7 @@ while true @@ -35,7 +35,7 @@ while true
35 comentariosExtraidos = comentariosExtraidos.uniq 35 comentariosExtraidos = comentariosExtraidos.uniq
36 36
37 if primeiraVez 37 if primeiraVez
38 - comentariosIniciais=comentariosExtraidos.clone 38 + comentariosIniciais=comentariosExtraidos.clone
39 primeiraVez = false 39 primeiraVez = false
40 end 40 end
41 41
@@ -45,7 +45,7 @@ while true @@ -45,7 +45,7 @@ while true
45 45
46 comentariosNovos = comentariosExtraidos - comentariosIniciais 46 comentariosNovos = comentariosExtraidos - comentariosIniciais
47 comentariosNovos = comentariosNovos.uniq 47 comentariosNovos = comentariosNovos.uniq
48 - comentariosIniciais += comentariosNovos 48 + comentariosIniciais += comentariosNovos
49 comentariosIniciais = comentariosIniciais.uniq 49 comentariosIniciais = comentariosIniciais.uniq
50 comentariosNovos.each{|comentario| 50 comentariosNovos.each{|comentario|
51 puts comentario 51 puts comentario
plugins/community_hub/facebook_stream/lib_facebook_stream.rb 0 → 100644
@@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
  1 +require 'rubygems'
  2 +require 'koala'
  3 +require 'json'
  4 +
  5 +#Warning!!! Warning!!! Warning!!! Warning!!! Warning!!! Warning!!! Warning!!! Warning!!!
  6 +#token will expire at 12/04/2014 (Brazilian date format) + 59 days
  7 +#'CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH'
  8 +# BACKUP TOKEN 'CAAEhsewl0ZAcBAHhipXszZCURSwWLmgvceDbs9mB5baJdLriFxYMEzywmF2fvZBuThuA2Mm7QF8wPd3E6R5pVqVEnC2VhcBb4VrfAnkZC73ZC5g1NRUnKZCB2e6CaRiUBDatR2nf505PeKp7Aj5XxvTdfSqdZCsXxQFYZApPNSUUgkUWm6HwL4rp21MRJXb612sZD'
  9 +
  10 +def facebook_comments(hub, author_id, page_id="participabr", pooling_time=5, token='CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH')
  11 +
  12 + #raise hub.id.inspect
  13 + @graph = Koala::Facebook::API.new(token)
  14 + initialComments = []
  15 + extractedComments = []
  16 + firstTime = true
  17 + while true
  18 + feed = @graph.get_connections(page_id, "posts")
  19 + array = []
  20 + extractedComments = []
  21 + feed.each {|f|
  22 + if f['comments'] != nil && f['comments']['data'] != nil
  23 + array.push(f['comments']['data'])
  24 + end
  25 + }
  26 + array.each{ |comments|
  27 + comments.each{|comment|
  28 + extractedComments.push("#{comment['from']['name']} " + _("said") + ": #{comment['message']}")
  29 + }
  30 + }
  31 + extractedComments = extractedComments.uniq
  32 + if firstTime
  33 + initialComments=extractedComments.clone
  34 + firstTime = false
  35 + end
  36 + newComments = extractedComments - initialComments
  37 + newComments = newComments.uniq
  38 + initialComments += newComments
  39 + initialComments = initialComments.uniq
  40 + newComments.each{|comment|
  41 + puts comment
  42 + noosferoComment = Comment.new
  43 + noosferoComment.source_id = hub.id
  44 + noosferoComment.body = comment
  45 + noosferoComment.author_id = author_id
  46 + noosferoComment.save!
  47 + }
  48 + sleep(pooling_time)
  49 + end
  50 +end
0 \ No newline at end of file 51 \ No newline at end of file
plugins/community_hub/lib/community_hub_plugin/hub.rb
1 -#require File.dirname(__FILE__) + '/../../tweeter_stream/lib/twurl' 1 +require File.dirname(__FILE__) + '/../../tweeter_stream/lib/twurl'
  2 +require File.dirname(__FILE__) + '/../../facebook_stream/lib_facebook_stream'
2 3
3 class CommunityHubPlugin::Hub < Folder 4 class CommunityHubPlugin::Hub < Folder
4 5
  6 + @@twitter_thread_started = false #change to hash
  7 + @@facebook_thread_started = false #change to hash
  8 +
5 settings_items :hashtags_twitter, :type => :string, :default => "" 9 settings_items :hashtags_twitter, :type => :string, :default => ""
6 settings_items :twitter_enabled, :type => :boolean, :default => false 10 settings_items :twitter_enabled, :type => :boolean, :default => false
7 settings_items :facebook_enabled, :type => :boolean, :default => false 11 settings_items :facebook_enabled, :type => :boolean, :default => false
@@ -9,12 +13,10 @@ class CommunityHubPlugin::Hub &lt; Folder @@ -9,12 +13,10 @@ class CommunityHubPlugin::Hub &lt; Folder
9 settings_items :pinned_mediations, :type => Array, :default => [] 13 settings_items :pinned_mediations, :type => Array, :default => []
10 settings_items :mediators, :type => Array, :default => [] 14 settings_items :mediators, :type => Array, :default => []
11 15
12 - #@@thread_started = false  
13 -  
14 before_create do |hub| 16 before_create do |hub|
15 hub.mediators = [hub.author.id] 17 hub.mediators = [hub.author.id]
16 end 18 end
17 - 19 +
18 def self.icon_name(article = nil) 20 def self.icon_name(article = nil)
19 'community-hub' 21 'community-hub'
20 end 22 end
@@ -31,29 +33,29 @@ class CommunityHubPlugin::Hub &lt; Folder @@ -31,29 +33,29 @@ class CommunityHubPlugin::Hub &lt; Folder
31 true 33 true
32 end 34 end
33 35
34 -# def self.start_twitter_service(page)  
35 -  
36 -# a = Thread.new {  
37 -# Twurl::Stream.run(page, 'nba', '/root/.twurlrc')  
38 -# } unless @@thread_started  
39 -  
40 -# @@thread_started = true  
41 -  
42 -# raise page.inspect  
43 -  
44 -# comment = Comment.new  
45 -# comment.source_id = page.id  
46 -# comment.body = "Teste Evandro"  
47 -# comment.author_id = "54"  
48 -# comment.save!  
49 -  
50 -  
51 -# raise "Pai #{parent.id}".inspect  
52 -  
53 -# end 36 + def self.twitter_service(hub, action)
  37 + author_id = 54
  38 + if action==:start
  39 + thread = Thread.new {
  40 + Twurl::Stream.run(hub, author_id,'torrent', File.dirname(__FILE__) + '/../../tweeter_stream/config/twurlrc')
  41 + } unless@@twitter_thread_started
  42 + @@twitter_thread_started = true
  43 + end
  44 + end
  45 +
  46 + def self.facebook_service(hub, action)
  47 + author_id = 54
  48 + page_id="mundoreagindo"
  49 + if action==:start
  50 + #facebook_comments(page, author_id, page_id, pooling_time=5, token='CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH')
  51 + thread = Thread.new {
  52 + facebook_comments(hub, author_id, page_id)
  53 + } unless@@facebook_thread_started
  54 + @@facebook_thread_started = true
  55 + end
  56 + end
54 57
55 def view_page 58 def view_page
56 "content_viewer/hub.rhtml" 59 "content_viewer/hub.rhtml"
57 end 60 end
58 -  
59 end 61 end
60 \ No newline at end of file 62 \ No newline at end of file
plugins/community_hub/tweeter_stream/.twurlrc
@@ -1,13 +0,0 @@ @@ -1,13 +0,0 @@
1 ----  
2 -profiles:  
3 - evandro:  
4 - QkiWnQvutoV63ty0Afg:  
5 - token: 8601482-U3qvrGvZmKgm5HnTCskdYU2bAoMPzNpXcLtdVzhKQx  
6 - consumer_key: QkiWnQvutoV63ty0Afg  
7 - username: evandro  
8 - consumer_secret: kCLHpOG2p3073mYsxrTYyvwkOulYbtIcxpQkthJU  
9 - secret: eCzPWQOcUdcADRmFjqQTIXPbmieOxMpXDj7RUS6mVrPru  
10 -configuration:  
11 - default_profile:  
12 - - evandro  
13 - - QkiWnQvutoV63ty0Afg  
plugins/community_hub/tweeter_stream/config/twurlrc 0 → 100644
@@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
  1 +---
  2 +profiles:
  3 + evandro:
  4 + QkiWnQvutoV63ty0Afg:
  5 + token: 8601482-U3qvrGvZmKgm5HnTCskdYU2bAoMPzNpXcLtdVzhKQx
  6 + consumer_key: QkiWnQvutoV63ty0Afg
  7 + username: evandro
  8 + consumer_secret: kCLHpOG2p3073mYsxrTYyvwkOulYbtIcxpQkthJU
  9 + secret: eCzPWQOcUdcADRmFjqQTIXPbmieOxMpXDj7RUS6mVrPru
  10 +configuration:
  11 + default_profile:
  12 + - evandro
  13 + - QkiWnQvutoV63ty0Afg
plugins/community_hub/tweeter_stream/lib/twurl/request_controller.rb
1 require "json" 1 require "json"
  2 +require 'iconv'
2 3
3 module Twurl 4 module Twurl
4 class RequestController < AbstractCommandController 5 class RequestController < AbstractCommandController
@@ -14,17 +15,20 @@ module Twurl @@ -14,17 +15,20 @@ module Twurl
14 def perform_request 15 def perform_request
15 client.perform_request_from_options(options) { |response| 16 client.perform_request_from_options(options) { |response|
16 response.read_body { |chunk| 17 response.read_body { |chunk|
17 -# print "#{chunk}\n" 18 +# print "#{chunk}\n"
18 #unless chunk.to_i.length = 0 19 #unless chunk.to_i.length = 0
19 begin 20 begin
20 parsed = JSON.parse(chunk) 21 parsed = JSON.parse(chunk)
21 -# print "@#{parsed["user"]["name"]} said: #{parsed["text"]} \n" 22 + ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
  23 + comment_text = ic.iconv("@#{parsed["user"]["name"]} " + _('said') + ": #{parsed["text"]}" + ' ')[0..-2]
  24 + print "#{comment_text}\n"
22 comment = Comment.new 25 comment = Comment.new
23 comment.source_id = Stream.page.id 26 comment.source_id = Stream.page.id
24 - comment.body = parsed["text"]  
25 - comment.author_id = "54" 27 + comment.body = comment_text
  28 + comment.author_id = Stream.author_id
26 comment.save! 29 comment.save!
27 rescue 30 rescue
  31 + print "Erro gravando comentário twitter\n"
28 end 32 end
29 #raise comment.inspect 33 #raise comment.inspect
30 # rescue 34 # rescue
plugins/community_hub/tweeter_stream/lib/twurl/stream.rb
@@ -6,16 +6,16 @@ module Twurl @@ -6,16 +6,16 @@ module Twurl
6 PATH_PATTERN = /^\/\w+/ 6 PATH_PATTERN = /^\/\w+/
7 PROTOCOL_PATTERN = /^\w+:\/\// 7 PROTOCOL_PATTERN = /^\w+:\/\//
8 README = File.dirname(__FILE__) + '/../../README' 8 README = File.dirname(__FILE__) + '/../../README'
9 - @output ||= STDOUT 9 + @output ||= STDOUT
10 class NoPathFound < Exception 10 class NoPathFound < Exception
11 end 11 end
12 12
13 class << self 13 class << self
14 attr_accessor :output 14 attr_accessor :output
15 -  
16 - def run(page, tags, config_file_path, proxy=nil) 15 + def run(page, author_id, tags, config_file_path, proxy=nil)
17 begin 16 begin
18 @page = page # maybe should not be a class variable 17 @page = page # maybe should not be a class variable
  18 + @author_id = author_id
19 @@file_path = config_file_path 19 @@file_path = config_file_path
20 Twurl.options = Options.new 20 Twurl.options = Options.new
21 Twurl.options.command = 'request' # Not necessary anymore 21 Twurl.options.command = 'request' # Not necessary anymore
@@ -30,7 +30,6 @@ module Twurl @@ -30,7 +30,6 @@ module Twurl
30 Twurl.options.path="/1.1/statuses/filter.json" 30 Twurl.options.path="/1.1/statuses/filter.json"
31 Twurl.options.host="stream.twitter.com" 31 Twurl.options.host="stream.twitter.com"
32 Twurl.options.read_timeout= 0 32 Twurl.options.read_timeout= 0
33 -  
34 rescue NoPathFound => e 33 rescue NoPathFound => e
35 exit 34 exit
36 end 35 end
@@ -40,6 +39,10 @@ module Twurl @@ -40,6 +39,10 @@ module Twurl
40 def file_path 39 def file_path
41 @@file_path 40 @@file_path
42 end 41 end
  42 +
  43 + def author_id
  44 + @author_id
  45 + end
43 46
44 def page 47 def page
45 @page 48 @page
plugins/community_hub/views/content_viewer/hub.rhtml
1 <% extend CommunityHubPlugin::HubHelper %> 1 <% extend CommunityHubPlugin::HubHelper %>
2 2
  3 +<% CommunityHubPlugin::Hub.twitter_service(@page, :start) %>
  4 +<% CommunityHubPlugin::Hub.facebook_service(@page, :start) %>
  5 +
3 <div id="<%=@page.id%>" class="hub"> 6 <div id="<%=@page.id%>" class="hub">
4 7
5 <div class="title"><%= @page.title %> HUB</div> 8 <div class="title"><%= @page.title %> HUB</div>