Commit 704c90fdc4180e4db4bdbe206f38bc3cb4b24a93
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'AI3074-community_dashboard' of gitlab.com:participa/noosfero into …
…AI3074-community_dashboard
Showing
4 changed files
with
52 additions
and
32 deletions
Show diff stats
plugins/community_hub/lib/community_hub_plugin/hub.rb
| @@ -38,34 +38,7 @@ class CommunityHubPlugin::Hub < Folder | @@ -38,34 +38,7 @@ class CommunityHubPlugin::Hub < Folder | ||
| 38 | true | 38 | true |
| 39 | end | 39 | end |
| 40 | 40 | ||
| 41 | - def twitter_service | ||
| 42 | - Twurl::Stream.run(self, nil, hashtags_twitter, File.dirname(__FILE__) + '/../../tweeter_stream/config/twurlrc', proxy_url) | ||
| 43 | - end | ||
| 44 | - | ||
| 45 | - def facebook_service | ||
| 46 | - facebook_comments(self, nil, facebook_page_id, facebook_pooling_time, facebook_access_token, proxy_url) | ||
| 47 | - end | ||
| 48 | - | ||
| 49 | - def self.start_listen | ||
| 50 | - hubs = {} | ||
| 51 | - loop do | ||
| 52 | - puts "searching for hubs" | ||
| 53 | - CommunityHubPlugin::Hub.all.each do |hub| | ||
| 54 | - hub_conf = hubs[hub.id] | ||
| 55 | - if hub_conf.nil? || hub_conf[:hub].updated_at < hub.updated_at | ||
| 56 | - hub_conf[:threads].each {|t| t.terminate} if hub_conf | ||
| 57 | - puts "hub #{hub.id} found!!!!!!" | ||
| 58 | - threads = [] | ||
| 59 | - threads << Thread.new { hub.twitter_service } if hub.twitter_enabled | ||
| 60 | - threads << Thread.new { hub.facebook_service } if hub.facebook_enabled | ||
| 61 | - hubs[hub.id] = {:threads => threads, :hub => hub} | ||
| 62 | - end | ||
| 63 | - end | ||
| 64 | - sleep(5) | ||
| 65 | - end | ||
| 66 | - end | ||
| 67 | - | ||
| 68 | def view_page | 41 | def view_page |
| 69 | "content_viewer/hub.rhtml" | 42 | "content_viewer/hub.rhtml" |
| 70 | end | 43 | end |
| 71 | -end | ||
| 72 | \ No newline at end of file | 44 | \ No newline at end of file |
| 45 | +end |
plugins/community_hub/lib/community_hub_plugin/listener.rb
0 → 100644
| @@ -0,0 +1,47 @@ | @@ -0,0 +1,47 @@ | ||
| 1 | +class CommunityHubPlugin::Listener | ||
| 2 | + | ||
| 3 | + class << self | ||
| 4 | + | ||
| 5 | + def twitter_service(hub) | ||
| 6 | + Twurl::Stream.run(hub, nil, hub.hashtags_twitter, File.dirname(__FILE__) + '/../../tweeter_stream/config/twurlrc', hub.proxy_url) | ||
| 7 | + end | ||
| 8 | + | ||
| 9 | + def facebook_service(hub) | ||
| 10 | + facebook_comments(hub, nil, hub.facebook_page_id, hub.facebook_pooling_time, hub.facebook_access_token, hub.proxy_url) | ||
| 11 | + end | ||
| 12 | + | ||
| 13 | + def run | ||
| 14 | + hubs = {} | ||
| 15 | + loop do | ||
| 16 | + log "searching for hubs" | ||
| 17 | + CommunityHubPlugin::Hub.all.each do |hub| | ||
| 18 | + hub_conf = hubs[hub.id] | ||
| 19 | + if hub_conf.nil? || hub_conf[:hub].updated_at < hub.updated_at | ||
| 20 | + hub_conf[:threads].each {|t| t.terminate} if hub_conf | ||
| 21 | + log "hub #{hub.id} found!!!!!!" | ||
| 22 | + threads = [] | ||
| 23 | + threads << Thread.new { twitter_service(hub) } if hub.twitter_enabled | ||
| 24 | + threads << Thread.new { facebook_service(hub) } if hub.facebook_enabled | ||
| 25 | + hubs[hub.id] = {:threads => threads, :hub => hub} | ||
| 26 | + end | ||
| 27 | + end | ||
| 28 | + sleep(10) | ||
| 29 | + end | ||
| 30 | + end | ||
| 31 | + | ||
| 32 | + def initialize_logger | ||
| 33 | + logdir = File.join(RAILS_ROOT, 'log', CommunityHubPlugin::Listener.name.underscore) | ||
| 34 | + File.makedirs(logdir) if !File.exist?(logdir) | ||
| 35 | + logpath = File.join(logdir, "#{ENV['RAILS_ENV']}_#{Time.now.strftime('%F')}.log") | ||
| 36 | + @logger = Logger.new(logpath) | ||
| 37 | + end | ||
| 38 | + | ||
| 39 | + def log(message) | ||
| 40 | + initialize_logger unless @initiated | ||
| 41 | + @initiated ||= true | ||
| 42 | + @logger << "[#{Time.now.strftime('%F %T %z')}] #{message}\n" | ||
| 43 | + end | ||
| 44 | + | ||
| 45 | + end | ||
| 46 | + | ||
| 47 | +end |
plugins/community_hub/script/hub_updater
| @@ -7,5 +7,5 @@ NOOSFERO_ROOT = File.expand_path(File.dirname(__FILE__) + '/../../../') | @@ -7,5 +7,5 @@ NOOSFERO_ROOT = File.expand_path(File.dirname(__FILE__) + '/../../../') | ||
| 7 | 7 | ||
| 8 | Daemons.run_proc('hub') do | 8 | Daemons.run_proc('hub') do |
| 9 | require NOOSFERO_ROOT + '/config/environment' | 9 | require NOOSFERO_ROOT + '/config/environment' |
| 10 | - CommunityHubPlugin::Hub.start_listen | 10 | + CommunityHubPlugin::Listener.run |
| 11 | end | 11 | end |
plugins/community_hub/tweeter_stream/lib/twurl/request_controller.rb
| @@ -20,14 +20,14 @@ module Twurl | @@ -20,14 +20,14 @@ module Twurl | ||
| 20 | begin | 20 | begin |
| 21 | parsed = JSON.parse(chunk) | 21 | parsed = JSON.parse(chunk) |
| 22 | ic = Iconv.new('UTF-8//IGNORE', 'UTF-8') | 22 | ic = Iconv.new('UTF-8//IGNORE', 'UTF-8') |
| 23 | - comment_text = ic.iconv("@#{parsed["user"]["name"]} " + _('said') + ": #{parsed["text"]}" + ' ')[0..-2] | 23 | + comment_text = ic.iconv(parsed["text"])[0..-2] |
| 24 | print "#{comment_text}\n" | 24 | print "#{comment_text}\n" |
| 25 | comment = Comment.new | 25 | comment = Comment.new |
| 26 | - comment.title = 'hub-message-twitter' | 26 | + comment.title = 'hub-message-twitter' |
| 27 | comment.source = options.page | 27 | comment.source = options.page |
| 28 | comment.body = comment_text | 28 | comment.body = comment_text |
| 29 | comment.author_id = options.author_id | 29 | comment.author_id = options.author_id |
| 30 | - comment.name = parsed["user"]["name"] | 30 | + comment.name = ic.iconv(parsed["user"]["name"])[0..-2] |
| 31 | comment.email = 'admin@localhost.local' | 31 | comment.email = 'admin@localhost.local' |
| 32 | comment.save! | 32 | comment.save! |
| 33 | rescue => e | 33 | rescue => e |