diff --git a/plugins/community_hub/lib/community_hub_plugin/hub.rb b/plugins/community_hub/lib/community_hub_plugin/hub.rb index 14b87df..f17a9f4 100644 --- a/plugins/community_hub/lib/community_hub_plugin/hub.rb +++ b/plugins/community_hub/lib/community_hub_plugin/hub.rb @@ -3,9 +3,6 @@ require File.dirname(__FILE__) + '/../../facebook_stream/lib_facebook_stream' class CommunityHubPlugin::Hub < Folder - @@twitter_thread_started = false #change to hash - @@facebook_thread_started = false #change to hash - settings_items :proxy_url, :type => :string, :default => 'http://161.148.1.167:312' # Remember to use add the port, if needed! settings_items :twitter_enabled, :type => :boolean, :default => false settings_items :hashtags_twitter, :type => :string, :default => "participa.br,participabr,arenanetmundial,netmundial" @@ -20,7 +17,7 @@ class CommunityHubPlugin::Hub < Folder before_create do |hub| hub.mediators = [hub.author.id] end - + def self.icon_name(article = nil) 'community-hub' end @@ -37,26 +34,33 @@ class CommunityHubPlugin::Hub < Folder true end - def self.twitter_service(hub, action) - author_id = 54 - if action==:start - thread = Thread.new { - Twurl::Stream.run(hub, author_id, hub.setting[:hashtags_twitter], File.dirname(__FILE__) + '/../../tweeter_stream/config/twurlrc', hub.setting[:proxy_url]) - } unless@@twitter_thread_started - @@twitter_thread_started = true - end + def twitter_service + Twurl::Stream.run(self, nil, hashtags_twitter, File.dirname(__FILE__) + '/../../tweeter_stream/config/twurlrc', proxy_url) end - - def self.facebook_service(hub, action) - author_id = 54 - if action==:start - thread = Thread.new { - facebook_comments(hub, author_id, hub.setting[:facebook_page_id], hub.setting[:facebook_pooling_time], hub.setting[:facebook_access_token], hub.setting[:proxy_url]) - } unless@@facebook_thread_started - @@facebook_thread_started = true + + def facebook_service + facebook_comments(self, nil, facebook_page_id, facebook_pooling_time, facebook_access_token, proxy_url) + end + + def self.start_listen + hubs = {} + loop do + puts "searching for hubs" + CommunityHubPlugin::Hub.all.each do |hub| + hub_conf = hubs[hub.id] + if hub_conf.nil? || hub_conf[:hub].updated_at < hub.updated_at + hub_conf[:threads].each {|t| t.terminate} if hub_conf + puts "hub #{hub.id} found!!!!!!" + threads = [] + threads << Thread.new { hub.twitter_service } if hub.twitter_enabled + threads << Thread.new { hub.facebook_service } if hub.facebook_enabled + hubs[hub.id] = {:threads => threads, :hub => hub} + end end + sleep(5) + end end - + def view_page "content_viewer/hub.rhtml" end diff --git a/plugins/community_hub/script/hub_updater b/plugins/community_hub/script/hub_updater new file mode 100755 index 0000000..712f806 --- /dev/null +++ b/plugins/community_hub/script/hub_updater @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby + +require 'daemons' +require 'optparse' + +NOOSFERO_ROOT = File.expand_path(File.dirname(__FILE__) + '/../../../') + +Daemons.run_proc('hub') do + require NOOSFERO_ROOT + '/config/environment' + CommunityHubPlugin::Hub.start_listen +end diff --git a/plugins/community_hub/tweeter_stream/lib/twurl/request_controller.rb b/plugins/community_hub/tweeter_stream/lib/twurl/request_controller.rb index ec995a9..e00d7ca 100755 --- a/plugins/community_hub/tweeter_stream/lib/twurl/request_controller.rb +++ b/plugins/community_hub/tweeter_stream/lib/twurl/request_controller.rb @@ -15,8 +15,8 @@ module Twurl def perform_request client.perform_request_from_options(options) { |response| response.read_body { |chunk| -# print "#{chunk}\n" - #unless chunk.to_i.length = 0 + #print "chunk: #{chunk}\n" + unless chunk.blank? begin parsed = JSON.parse(chunk) ic = Iconv.new('UTF-8//IGNORE', 'UTF-8') @@ -24,17 +24,16 @@ module Twurl print "#{comment_text}\n" comment = Comment.new comment.title = 'hub-message-twitter' - comment.source_id = Stream.page.id + comment.source_id = options.page.id comment.body = comment_text - comment.author_id = Stream.author_id - comment.save! - rescue - print "Erro gravando comentário twitter\n" - end - #raise comment.inspect -# rescue -# end - #end + comment.author_id = options.author_id + comment.name = parsed["user"]["name"] + comment.email = 'admin@localhost.local' + comment.save! + rescue => e + print "Erro gravando comentário twitter #{e}\n" + end + end } } rescue URI::InvalidURIError diff --git a/plugins/community_hub/tweeter_stream/lib/twurl/stream.rb b/plugins/community_hub/tweeter_stream/lib/twurl/stream.rb index a7b69cd..1ab83d4 100755 --- a/plugins/community_hub/tweeter_stream/lib/twurl/stream.rb +++ b/plugins/community_hub/tweeter_stream/lib/twurl/stream.rb @@ -14,8 +14,6 @@ module Twurl attr_accessor :output 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,6 +28,8 @@ module Twurl Twurl.options.path="/1.1/statuses/filter.json" Twurl.options.host="stream.twitter.com" Twurl.options.read_timeout= 0 + Twurl.options.page = page + Twurl.options.author_id = author_id rescue NoPathFound => e exit end @@ -40,14 +40,6 @@ module Twurl @@file_path end - def author_id - @author_id - end - - def page - @page - end - def dispatch(options) client = OAuthClient.load_from_options(options) controller = RequestController diff --git a/plugins/community_hub/tweeter_stream/noosfero.rb b/plugins/community_hub/tweeter_stream/noosfero.rb index ca9ed68..b3836de 100755 --- a/plugins/community_hub/tweeter_stream/noosfero.rb +++ b/plugins/community_hub/tweeter_stream/noosfero.rb @@ -3,4 +3,4 @@ require 'rubygems' # if you use RubyGems require File.dirname(__FILE__) + '/lib/twurl' -Twurl::Stream.run('popcorntime,time4popcorn', '/root/.twurlrc') +Twurl::Stream.run(Article.last, 1, '#nba', '/home/00838716598/participa/noosfero/plugins/community_hub/tweeter_stream/config/twurlrc') diff --git a/plugins/community_hub/views/community_hub_plugin_public/_post.rhtml b/plugins/community_hub/views/community_hub_plugin_public/_post.rhtml index 7cc4187..8630523 100644 --- a/plugins/community_hub/views/community_hub_plugin_public/_post.rhtml +++ b/plugins/community_hub/views/community_hub_plugin_public/_post.rhtml @@ -9,7 +9,7 @@ <% elsif post.title == 'hub-message-facebook' %> <%= image_tag('/designs/themes/default/images/logo-facebook-50x50.png', :alt => "Facebook") %> <% else %> - <%= image_tag(profile_icon(post.author, :minor)) %> + <%= image_tag(profile_icon(post.author, :minor)) if post.author %> <% end %>
  • <%= post.author_name %>: <%= post.body %>
  • @@ -19,7 +19,7 @@ - \ No newline at end of file + diff --git a/plugins/community_hub/views/content_viewer/hub.rhtml b/plugins/community_hub/views/content_viewer/hub.rhtml index 9440fd9..bf2667b 100644 --- a/plugins/community_hub/views/content_viewer/hub.rhtml +++ b/plugins/community_hub/views/content_viewer/hub.rhtml @@ -1,8 +1,5 @@ <% extend CommunityHubPlugin::HubHelper %> -<% CommunityHubPlugin::Hub.twitter_service(@page, :start) %> -<% CommunityHubPlugin::Hub.facebook_service(@page, :start) %> -
    <%= @page.title %> HUB
    -- libgit2 0.21.2