Commit f0407afbfc235fd5cc0c9f262d1e9478c06f351b

Authored by Evandro Junior
1 parent ca863389

testing twitter and facebook feeds

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  
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
facebook_stream/lib_facebook_stream.rb 0 → 100644
@@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
  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_id, author_id, page_id="participabr", pooling_time=5, token='CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH')
  11 + @graph = Koala::Facebook::API.new(token)
  12 + initialComments = []
  13 + extractedComments = []
  14 + newComments = []
  15 + firstTime = true
  16 + while true
  17 + feed = @graph.get_connections(page_id, "posts")
  18 + array = []
  19 + extractedComments = []
  20 + feed.each {|f|
  21 + if f['comments'] != nil && f['comments']['data'] != nil
  22 + array.push(f['comments']['data'])
  23 + end
  24 + }
  25 + array.each{ |comments|
  26 + comments.each{|comment|
  27 + extractedComments.push("#{comment['from']['name']} " + _("said:") + " : #{comment['message']}")
  28 + }
  29 + }
  30 + extractedComments = extractedComments.uniq
  31 + if firstTime
  32 + initialComments=extractedComments.clone
  33 + firstTime = false
  34 + end
  35 + newComments = extractedComments - initialComments
  36 + newComments = newComments.uniq
  37 + initialCommentsinitialComments += newComments
  38 + initialComments = initialComments.uniq
  39 + newComments.each{|comment|
  40 + puts comment
  41 + noosferoComment = Comment.new
  42 + noosferoComment.source_id = hub_id
  43 + noosferoComment.body = comment
  44 + noosferoComment.author_id = author_id
  45 + noosferoComment.save!
  46 + }
  47 + sleep(pooling_time)
  48 + end
  49 +end
0 \ No newline at end of file 50 \ No newline at end of file
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 - 2 +require File.dirname(__FILE__) + '/../../facebook_stream/lib_facebook_stream'
3 3
4 class CommunityHubPlugin::Hub < Folder 4 class CommunityHubPlugin::Hub < Folder
5 5
@@ -7,7 +7,8 @@ class CommunityHubPlugin::Hub &lt; Folder @@ -7,7 +7,8 @@ class CommunityHubPlugin::Hub &lt; Folder
7 settings_items :promoted_users, :type => Array, :default => [] 7 settings_items :promoted_users, :type => Array, :default => []
8 settings_items :pinned_posts, :type => Array, :default => [] 8 settings_items :pinned_posts, :type => Array, :default => []
9 9
10 - @@thread_started = false 10 + @@twitter_thread_started = false
  11 + @@facebook_thread_started = false
11 12
12 def self.icon_name(article = nil) 13 def self.icon_name(article = nil)
13 'community-hub' 14 'community-hub'
@@ -25,26 +26,30 @@ class CommunityHubPlugin::Hub &lt; Folder @@ -25,26 +26,30 @@ class CommunityHubPlugin::Hub &lt; Folder
25 true 26 true
26 end 27 end
27 28
28 - def self.start_twitter_service(page)  
29 -  
30 - a = Thread.new {  
31 - Twurl::Stream.run(page, 'nba', '/root/.twurlrc')  
32 - } unless @@thread_started  
33 -  
34 - @@thread_started = true  
35 -  
36 -# raise page.inspect  
37 -  
38 -# comment = Comment.new  
39 -# comment.source_id = page.id  
40 -# comment.body = "Teste Evandro"  
41 -# comment.author_id = "54"  
42 -# comment.save!  
43 -  
44 -  
45 -# raise "Pai #{parent.id}".inspect  
46 - 29 + def self.twitter_service(page, action)
  30 + action=:start
  31 + if action==:start
  32 + thread = Thread.new {
  33 + Twurl::Stream.run(page, author_id,'torrent', File.dirname(__FILE__) + '/../../tweeter_stream/config/.twurlrc')
  34 + } unless@@twitter_thread_started
  35 + @@twitter_thread_started = true
  36 + end
  37 + end
  38 +
  39 + def self.facebook_service(page, action)
  40 + action=:start
  41 + page_id="mundoreagindo"
  42 + if action==:start
  43 + thread = Thread.new {
  44 + #facebook_comments(page, author_id, page_id, pooling_time=5, token='CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH')
  45 +# raise "entrou".inpect
  46 + facebook_comments(page, author_id, page_id)
  47 + } unless@@facebook_thread_started
  48 + @@facebook_thread_started = true
  49 + end
47 end 50 end
  51 +
  52 +
48 53
49 def view_page 54 def view_page
50 "content_viewer/hub.rhtml" 55 "content_viewer/hub.rhtml"
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  
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
tweeter_stream/lib/twurl/request_controller.rb
@@ -22,7 +22,7 @@ module Twurl @@ -22,7 +22,7 @@ module Twurl
22 comment = Comment.new 22 comment = Comment.new
23 comment.source_id = Stream.page.id 23 comment.source_id = Stream.page.id
24 comment.body = parsed["text"] 24 comment.body = parsed["text"]
25 - comment.author_id = "54" 25 + comment.author_id = Stream.author_id
26 comment.save! 26 comment.save!
27 rescue 27 rescue
28 end 28 end
tweeter_stream/lib/twurl/stream.rb
@@ -12,10 +12,10 @@ module Twurl @@ -12,10 +12,10 @@ module Twurl
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
views/content_viewer/hub.rhtml
1 <% extend CommunityHubPlugin::HubHelper %> 1 <% extend CommunityHubPlugin::HubHelper %>
2 2
3 -<% CommunityHubPlugin::Hub.start_twitter_service(@page) %> 3 +<% CommunityHubPlugin::Hub.twitter_service(@page, :start) %>
  4 +<% CommunityHubPlugin::Hub.facebook_service(@page, :start) %>
4 5
5 <div id="<%=@page.id%>" class="hub"> 6 <div id="<%=@page.id%>" class="hub">
6 7