Commit 8f0a3a1026b3e8033504be7456690b3fcb7b7449
1 parent
7add9925
Exists in
community_hub_submodule
new facebook library
Showing
1 changed file
with
76 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,76 @@ |
| 1 | +require 'rubygems' | |
| 2 | +require 'open-uri' | |
| 3 | +require 'json' | |
| 4 | + | |
| 5 | +token = 'CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH' | |
| 6 | +hashtag = "#nba" | |
| 7 | +pooling_time = 5 | |
| 8 | + | |
| 9 | + | |
| 10 | +#Aviso 12/04/2014 | |
| 11 | +#token que só deverá expirar em 59 dias | |
| 12 | +#@graph = Koala::Facebook::API.new('CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH') | |
| 13 | +# https://graph.facebook.com/v1.0/search?q=%23nba&type=post&access_token=CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH | |
| 14 | + | |
| 15 | +def not_blank(v) | |
| 16 | + if v == nil || v == "" | |
| 17 | + false | |
| 18 | + else | |
| 19 | + true | |
| 20 | + end | |
| 21 | +end | |
| 22 | + | |
| 23 | +if hashtag[0]='#' | |
| 24 | + hashtag = hashtag[1,hashtag.length-1] | |
| 25 | +end | |
| 26 | + | |
| 27 | +file = open("https://graph.facebook.com/v1.0/search?q=%23#{hashtag}&type=post&access_token=#{token}") | |
| 28 | +itens = JSON.parse(file.read)['data'] | |
| 29 | + | |
| 30 | +extractedComments = [] | |
| 31 | +initialComments = [] | |
| 32 | +firstTime = true | |
| 33 | +while true | |
| 34 | + mostRecent = "" | |
| 35 | + itens.each{|i| | |
| 36 | + from = "" | |
| 37 | + message = "" | |
| 38 | + if not_blank(i['from']['name']) | |
| 39 | + from = i['from']['name'] | |
| 40 | + if not_blank(i['message']) | |
| 41 | + message += i['message'] | |
| 42 | + end | |
| 43 | + if not_blank(message) | |
| 44 | + if mostRecent == "" or mostRecent > i["updated_time"] | |
| 45 | + mostRecent = i["updated_time"] | |
| 46 | + end | |
| 47 | + | |
| 48 | + extractedComments.push("#{from} said: #{message}") | |
| 49 | + # puts "#{from} said: #{message}" | |
| 50 | + end | |
| 51 | + end | |
| 52 | + } | |
| 53 | + | |
| 54 | + extractedComments = extractedComments.uniq | |
| 55 | + if firstTime | |
| 56 | + initialComments = extractedComments.clone | |
| 57 | + firstTime = false | |
| 58 | + end | |
| 59 | + | |
| 60 | +# extractedComments.each{|comment| | |
| 61 | +# puts comment | |
| 62 | +# } | |
| 63 | + | |
| 64 | + newComments = extractedComments - initialComments | |
| 65 | + newComments = newComments.uniq | |
| 66 | + initialComments += newComments | |
| 67 | + initialComments = initialComments.uniq | |
| 68 | + newComments.each{|comment| | |
| 69 | + puts comment | |
| 70 | + } | |
| 71 | + puts "most recent post at #{mostRecent}" | |
| 72 | + sleep(pooling_time) | |
| 73 | +end | |
| 74 | + | |
| 75 | + | |
| 76 | + | ... | ... |