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 | 38 | true |
39 | 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 | 41 | def view_page |
69 | 42 | "content_viewer/hub.rhtml" |
70 | 43 | end |
71 | -end | |
72 | 44 | \ No newline at end of file |
45 | +end | ... | ... |
plugins/community_hub/lib/community_hub_plugin/listener.rb
0 → 100644
... | ... | @@ -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
plugins/community_hub/tweeter_stream/lib/twurl/request_controller.rb
... | ... | @@ -20,14 +20,14 @@ module Twurl |
20 | 20 | begin |
21 | 21 | parsed = JSON.parse(chunk) |
22 | 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 | 24 | print "#{comment_text}\n" |
25 | 25 | comment = Comment.new |
26 | - comment.title = 'hub-message-twitter' | |
26 | + comment.title = 'hub-message-twitter' | |
27 | 27 | comment.source = options.page |
28 | 28 | comment.body = comment_text |
29 | 29 | comment.author_id = options.author_id |
30 | - comment.name = parsed["user"]["name"] | |
30 | + comment.name = ic.iconv(parsed["user"]["name"])[0..-2] | |
31 | 31 | comment.email = 'admin@localhost.local' |
32 | 32 | comment.save! |
33 | 33 | rescue => e | ... | ... |