Commit 3318c1ba8d86e952c4b93efc21311e4e2d21ba5d
1 parent
eee9e13d
Exists in
community_hub_submodule
community-hub: fix facebook stream
Showing
1 changed file
with
16 additions
and
17 deletions
Show diff stats
facebook_stream/lib_facebook_stream.rb
| ... | ... | @@ -9,11 +9,13 @@ require 'json' |
| 9 | 9 | |
| 10 | 10 | def facebook_comments(hub, author_id, page_id, pooling_time, token, proxy_url) |
| 11 | 11 | if pooling_time == nil |
| 12 | - pooling_time = 5 | |
| 13 | - end | |
| 12 | + pooling_time = 5 | |
| 13 | + end | |
| 14 | + #Koala.http_service.http_options = { | |
| 15 | + # :proxy => 'http://161.148.1.167:3128' | |
| 16 | + #} | |
| 14 | 17 | @graph = Koala::Facebook::API.new(token) |
| 15 | 18 | initialComments = [] |
| 16 | - extractedComments = [] | |
| 17 | 19 | firstTime = true |
| 18 | 20 | while true |
| 19 | 21 | feed = @graph.get_connections(page_id, "posts") |
| ... | ... | @@ -24,12 +26,7 @@ def facebook_comments(hub, author_id, page_id, pooling_time, token, proxy_url) |
| 24 | 26 | array.push(f['comments']['data']) |
| 25 | 27 | end |
| 26 | 28 | } |
| 27 | - array.each{ |comments| | |
| 28 | - comments.each{|comment| | |
| 29 | - extractedComments.push("#{comment['from']['name']} " + _("said") + ": #{comment['message']}") | |
| 30 | - } | |
| 31 | - } | |
| 32 | - extractedComments = extractedComments.uniq | |
| 29 | + extractedComments = array.flatten.uniq | |
| 33 | 30 | if firstTime |
| 34 | 31 | initialComments=extractedComments.clone |
| 35 | 32 | firstTime = false |
| ... | ... | @@ -39,14 +36,16 @@ def facebook_comments(hub, author_id, page_id, pooling_time, token, proxy_url) |
| 39 | 36 | initialComments += newComments |
| 40 | 37 | initialComments = initialComments.uniq |
| 41 | 38 | newComments.each{|comment| |
| 42 | - puts comment | |
| 43 | - noosferoComment = Comment.new | |
| 44 | - noosferoComment.title = 'hub-message-facebook' | |
| 45 | - noosferoComment.source_id = hub.id | |
| 46 | - noosferoComment.body = comment | |
| 47 | - noosferoComment.author_id = author_id | |
| 48 | - noosferoComment.save! | |
| 39 | + puts "#{comment['from']['name']} " + _("said") + ": #{comment['message']}" | |
| 40 | + noosferoComment = Comment.new | |
| 41 | + noosferoComment.title = 'hub-message-facebook' | |
| 42 | + noosferoComment.source = hub | |
| 43 | + noosferoComment.body = comment['message'] | |
| 44 | + noosferoComment.author_id = author_id | |
| 45 | + noosferoComment.name = comment['from']['name'] | |
| 46 | + noosferoComment.email = 'admin@localhost.local' | |
| 47 | + noosferoComment.save! | |
| 49 | 48 | } |
| 50 | 49 | sleep(pooling_time) |
| 51 | 50 | end |
| 52 | -end | |
| 53 | 51 | \ No newline at end of file |
| 52 | +end | ... | ... |