diff --git a/facebook_stream/f_ainda_nao_expirou.rb b/facebook_stream/f_ainda_nao_expirou.rb deleted file mode 100755 index f563262..0000000 --- a/facebook_stream/f_ainda_nao_expirou.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'rubygems' -require 'koala' -require 'json' - -#@graph = Koala::Facebook::API.new('CAACEdEose0cBADWfQZB39lBDksRvjeJGGrkM3dYKTrWEG3G0m8eZCpq2Vf4dNnpAeKML3yxcTmxQ4ZAJfUcNMROrWFlonrkMiPMQlKcqLxSs9GhMWmMJvjHgPrhXJFIvBLD3Mlf0BIF89SLXlNFQj56DxtKkJpzZA8gzh0HCDGqsZA0b6kgPjPqJ2UIQsBZA4ZD') -@graph = Koala::Facebook::API.new('CAAEhsewl0ZAcBAHhipXszZCURSwWLmgvceDbs9mB5baJdLriFxYMEzywmF2fvZBuThuA2Mm7QF8wPd3E6R5pVqVEnC2VhcBb4VrfAnkZC73ZC5g1NRUnKZCB2e6CaRiUBDatR2nf505PeKp7Aj5XxvTdfSqdZCsXxQFYZApPNSUUgkUWm6HwL4rp21MRJXb612sZD') - -feed = @graph.get_connections("participabr", "posts") - -feed.each {|f| p f } -next_feed = feed.next_page diff --git a/facebook_stream/facebook_stream.rb b/facebook_stream/facebook_stream.rb index e9fdec5..8d60775 100755 --- a/facebook_stream/facebook_stream.rb +++ b/facebook_stream/facebook_stream.rb @@ -2,11 +2,11 @@ require 'rubygems' require 'koala' require 'json' +#Aviso 12/04/2014 #token que só deverá expirar em 59 dias @graph = Koala::Facebook::API.new('CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH') -#feed = @graph.get_connections("participabr", "posts") - +#feed = @graph.get_connections("participabr", "posts") comentariosIniciais = [] comentariosExtraidos = [] @@ -14,13 +14,13 @@ comentariosNovos = [] primeiraVez = true -while true +while true - feed = @graph.get_connections("mundoreagindo", "posts") + feed = @graph.get_connections("mundoreagindo", "posts") array = [] comentariosExtraidos = [] - feed.each {|f| + feed.each {|f| if f['comments'] != nil && f['comments']['data'] != nil array.push(f['comments']['data']) end @@ -35,7 +35,7 @@ while true comentariosExtraidos = comentariosExtraidos.uniq if primeiraVez - comentariosIniciais=comentariosExtraidos.clone + comentariosIniciais=comentariosExtraidos.clone primeiraVez = false end @@ -45,7 +45,7 @@ while true comentariosNovos = comentariosExtraidos - comentariosIniciais comentariosNovos = comentariosNovos.uniq - comentariosIniciais += comentariosNovos + comentariosIniciais += comentariosNovos comentariosIniciais = comentariosIniciais.uniq comentariosNovos.each{|comentario| puts comentario diff --git a/facebook_stream/lib_facebook_stream.rb b/facebook_stream/lib_facebook_stream.rb new file mode 100644 index 0000000..ace5d69 --- /dev/null +++ b/facebook_stream/lib_facebook_stream.rb @@ -0,0 +1,49 @@ +require 'rubygems' +require 'koala' +require 'json' + +#Warning!!! Warning!!! Warning!!! Warning!!! Warning!!! Warning!!! Warning!!! Warning!!! +#token will expire at 12/04/2014 (Brazilian date format) + 59 days +#'CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH' +# BACKUP TOKEN 'CAAEhsewl0ZAcBAHhipXszZCURSwWLmgvceDbs9mB5baJdLriFxYMEzywmF2fvZBuThuA2Mm7QF8wPd3E6R5pVqVEnC2VhcBb4VrfAnkZC73ZC5g1NRUnKZCB2e6CaRiUBDatR2nf505PeKp7Aj5XxvTdfSqdZCsXxQFYZApPNSUUgkUWm6HwL4rp21MRJXb612sZD' + +def facebook_comments(hub_id, author_id, page_id="participabr", pooling_time=5, token='CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH') + @graph = Koala::Facebook::API.new(token) + initialComments = [] + extractedComments = [] + newComments = [] + firstTime = true + while true + feed = @graph.get_connections(page_id, "posts") + array = [] + extractedComments = [] + feed.each {|f| + if f['comments'] != nil && f['comments']['data'] != nil + array.push(f['comments']['data']) + end + } + array.each{ |comments| + comments.each{|comment| + extractedComments.push("#{comment['from']['name']} " + _("said:") + " : #{comment['message']}") + } + } + extractedComments = extractedComments.uniq + if firstTime + initialComments=extractedComments.clone + firstTime = false + end + newComments = extractedComments - initialComments + newComments = newComments.uniq + initialCommentsinitialComments += newComments + initialComments = initialComments.uniq + newComments.each{|comment| + puts comment + noosferoComment = Comment.new + noosferoComment.source_id = hub_id + noosferoComment.body = comment + noosferoComment.author_id = author_id + noosferoComment.save! + } + sleep(pooling_time) + end +end \ No newline at end of file diff --git a/lib/community_hub_plugin/hub.rb b/lib/community_hub_plugin/hub.rb index d021e3c..14e0de9 100644 --- a/lib/community_hub_plugin/hub.rb +++ b/lib/community_hub_plugin/hub.rb @@ -1,5 +1,5 @@ require File.dirname(__FILE__) + '/../../tweeter_stream/lib/twurl' - +require File.dirname(__FILE__) + '/../../facebook_stream/lib_facebook_stream' class CommunityHubPlugin::Hub < Folder @@ -7,7 +7,8 @@ class CommunityHubPlugin::Hub < Folder settings_items :promoted_users, :type => Array, :default => [] settings_items :pinned_posts, :type => Array, :default => [] - @@thread_started = false + @@twitter_thread_started = false + @@facebook_thread_started = false def self.icon_name(article = nil) 'community-hub' @@ -25,26 +26,30 @@ class CommunityHubPlugin::Hub < Folder true end - def self.start_twitter_service(page) - - a = Thread.new { - Twurl::Stream.run(page, 'nba', '/root/.twurlrc') - } unless @@thread_started - - @@thread_started = true - -# raise page.inspect - -# comment = Comment.new -# comment.source_id = page.id -# comment.body = "Teste Evandro" -# comment.author_id = "54" -# comment.save! - - -# raise "Pai #{parent.id}".inspect - + def self.twitter_service(page, action) + action=:start + if action==:start + thread = Thread.new { + Twurl::Stream.run(page, author_id,'torrent', File.dirname(__FILE__) + '/../../tweeter_stream/config/.twurlrc') + } unless@@twitter_thread_started + @@twitter_thread_started = true + end + end + + def self.facebook_service(page, action) + action=:start + page_id="mundoreagindo" + if action==:start + thread = Thread.new { + #facebook_comments(page, author_id, page_id, pooling_time=5, token='CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH') +# raise "entrou".inpect + facebook_comments(page, author_id, page_id) + } unless@@facebook_thread_started + @@facebook_thread_started = true + end end + + def view_page "content_viewer/hub.rhtml" diff --git a/tweeter_stream/.twurlrc b/tweeter_stream/.twurlrc deleted file mode 100755 index aa4ad05..0000000 --- a/tweeter_stream/.twurlrc +++ /dev/null @@ -1,13 +0,0 @@ ---- -profiles: - evandro: - QkiWnQvutoV63ty0Afg: - token: 8601482-U3qvrGvZmKgm5HnTCskdYU2bAoMPzNpXcLtdVzhKQx - consumer_key: QkiWnQvutoV63ty0Afg - username: evandro - consumer_secret: kCLHpOG2p3073mYsxrTYyvwkOulYbtIcxpQkthJU - secret: eCzPWQOcUdcADRmFjqQTIXPbmieOxMpXDj7RUS6mVrPru -configuration: - default_profile: - - evandro - - QkiWnQvutoV63ty0Afg diff --git a/tweeter_stream/config/twurlrc b/tweeter_stream/config/twurlrc new file mode 100644 index 0000000..aa4ad05 --- /dev/null +++ b/tweeter_stream/config/twurlrc @@ -0,0 +1,13 @@ +--- +profiles: + evandro: + QkiWnQvutoV63ty0Afg: + token: 8601482-U3qvrGvZmKgm5HnTCskdYU2bAoMPzNpXcLtdVzhKQx + consumer_key: QkiWnQvutoV63ty0Afg + username: evandro + consumer_secret: kCLHpOG2p3073mYsxrTYyvwkOulYbtIcxpQkthJU + secret: eCzPWQOcUdcADRmFjqQTIXPbmieOxMpXDj7RUS6mVrPru +configuration: + default_profile: + - evandro + - QkiWnQvutoV63ty0Afg diff --git a/tweeter_stream/lib/twurl/request_controller.rb b/tweeter_stream/lib/twurl/request_controller.rb index f7ff2d7..2f31db2 100755 --- a/tweeter_stream/lib/twurl/request_controller.rb +++ b/tweeter_stream/lib/twurl/request_controller.rb @@ -22,7 +22,7 @@ module Twurl comment = Comment.new comment.source_id = Stream.page.id comment.body = parsed["text"] - comment.author_id = "54" + comment.author_id = Stream.author_id comment.save! rescue end diff --git a/tweeter_stream/lib/twurl/stream.rb b/tweeter_stream/lib/twurl/stream.rb index 05595bd..d83313d 100755 --- a/tweeter_stream/lib/twurl/stream.rb +++ b/tweeter_stream/lib/twurl/stream.rb @@ -12,10 +12,10 @@ module Twurl class << self attr_accessor :output - - def run(page, tags, config_file_path, proxy=nil) + def run(page, author_id, tags, config_file_path, proxy=nil) begin @page = page # maybe should not be a class variable + @author_id = author_id @@file_path = config_file_path Twurl.options = Options.new Twurl.options.command = 'request' # Not necessary anymore @@ -30,7 +30,6 @@ module Twurl Twurl.options.path="/1.1/statuses/filter.json" Twurl.options.host="stream.twitter.com" Twurl.options.read_timeout= 0 - rescue NoPathFound => e exit end @@ -40,6 +39,10 @@ module Twurl def file_path @@file_path end + + def author_id + @author_id + end def page @page diff --git a/views/content_viewer/hub.rhtml b/views/content_viewer/hub.rhtml index 44d95cc..c796ad6 100644 --- a/views/content_viewer/hub.rhtml +++ b/views/content_viewer/hub.rhtml @@ -1,6 +1,7 @@ <% extend CommunityHubPlugin::HubHelper %> -<% CommunityHubPlugin::Hub.start_twitter_service(@page) %> +<% CommunityHubPlugin::Hub.twitter_service(@page, :start) %> +<% CommunityHubPlugin::Hub.facebook_service(@page, :start) %>