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   -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 2 require 'koala'
3 3 require 'json'
4 4  
  5 +#Aviso 12/04/2014
5 6 #token que só deverá expirar em 59 dias
6 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 11 comentariosIniciais = []
12 12 comentariosExtraidos = []
... ... @@ -14,13 +14,13 @@ comentariosNovos = []
14 14  
15 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 21 array = []
22 22 comentariosExtraidos = []
23   - feed.each {|f|
  23 + feed.each {|f|
24 24 if f['comments'] != nil && f['comments']['data'] != nil
25 25 array.push(f['comments']['data'])
26 26 end
... ... @@ -35,7 +35,7 @@ while true
35 35 comentariosExtraidos = comentariosExtraidos.uniq
36 36  
37 37 if primeiraVez
38   - comentariosIniciais=comentariosExtraidos.clone
  38 + comentariosIniciais=comentariosExtraidos.clone
39 39 primeiraVez = false
40 40 end
41 41  
... ... @@ -45,7 +45,7 @@ while true
45 45  
46 46 comentariosNovos = comentariosExtraidos - comentariosIniciais
47 47 comentariosNovos = comentariosNovos.uniq
48   - comentariosIniciais += comentariosNovos
  48 + comentariosIniciais += comentariosNovos
49 49 comentariosIniciais = comentariosIniciais.uniq
50 50 comentariosNovos.each{|comentario|
51 51 puts comentario
... ...
plugins/community_hub/facebook_stream/lib_facebook_stream.rb 0 → 100644
... ... @@ -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 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 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 9 settings_items :hashtags_twitter, :type => :string, :default => ""
6 10 settings_items :twitter_enabled, :type => :boolean, :default => false
7 11 settings_items :facebook_enabled, :type => :boolean, :default => false
... ... @@ -9,12 +13,10 @@ class CommunityHubPlugin::Hub &lt; Folder
9 13 settings_items :pinned_mediations, :type => Array, :default => []
10 14 settings_items :mediators, :type => Array, :default => []
11 15  
12   - #@@thread_started = false
13   -
14 16 before_create do |hub|
15 17 hub.mediators = [hub.author.id]
16 18 end
17   -
  19 +
18 20 def self.icon_name(article = nil)
19 21 'community-hub'
20 22 end
... ... @@ -31,29 +33,29 @@ class CommunityHubPlugin::Hub &lt; Folder
31 33 true
32 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 58 def view_page
56 59 "content_viewer/hub.rhtml"
57 60 end
58   -
59 61 end
60 62 \ No newline at end of file
... ...
plugins/community_hub/tweeter_stream/.twurlrc
... ... @@ -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 @@
  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 1 require "json"
  2 +require 'iconv'
2 3  
3 4 module Twurl
4 5 class RequestController < AbstractCommandController
... ... @@ -14,17 +15,20 @@ module Twurl
14 15 def perform_request
15 16 client.perform_request_from_options(options) { |response|
16 17 response.read_body { |chunk|
17   -# print "#{chunk}\n"
  18 +# print "#{chunk}\n"
18 19 #unless chunk.to_i.length = 0
19 20 begin
20 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 25 comment = Comment.new
23 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 29 comment.save!
27 30 rescue
  31 + print "Erro gravando comentário twitter\n"
28 32 end
29 33 #raise comment.inspect
30 34 # rescue
... ...
plugins/community_hub/tweeter_stream/lib/twurl/stream.rb
... ... @@ -6,16 +6,16 @@ module Twurl
6 6 PATH_PATTERN = /^\/\w+/
7 7 PROTOCOL_PATTERN = /^\w+:\/\//
8 8 README = File.dirname(__FILE__) + '/../../README'
9   - @output ||= STDOUT
  9 + @output ||= STDOUT
10 10 class NoPathFound < Exception
11 11 end
12 12  
13 13 class << self
14 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 16 begin
18 17 @page = page # maybe should not be a class variable
  18 + @author_id = author_id
19 19 @@file_path = config_file_path
20 20 Twurl.options = Options.new
21 21 Twurl.options.command = 'request' # Not necessary anymore
... ... @@ -30,7 +30,6 @@ module Twurl
30 30 Twurl.options.path="/1.1/statuses/filter.json"
31 31 Twurl.options.host="stream.twitter.com"
32 32 Twurl.options.read_timeout= 0
33   -
34 33 rescue NoPathFound => e
35 34 exit
36 35 end
... ... @@ -40,6 +39,10 @@ module Twurl
40 39 def file_path
41 40 @@file_path
42 41 end
  42 +
  43 + def author_id
  44 + @author_id
  45 + end
43 46  
44 47 def page
45 48 @page
... ...
plugins/community_hub/views/content_viewer/hub.rhtml
1 1 <% extend CommunityHubPlugin::HubHelper %>
2 2  
  3 +<% CommunityHubPlugin::Hub.twitter_service(@page, :start) %>
  4 +<% CommunityHubPlugin::Hub.facebook_service(@page, :start) %>
  5 +
3 6 <div id="<%=@page.id%>" class="hub">
4 7  
5 8 <div class="title"><%= @page.title %> HUB</div>
... ...