Skip to content

Instantly share code, notes, and snippets.

@jubishop
Created April 28, 2009 04:22
Show Gist options
  • Save jubishop/102933 to your computer and use it in GitHub Desktop.
Save jubishop/102933 to your computer and use it in GitHub Desktop.
require 'net/http'
require 'uri'
require 'digest/md5'
api_key = 'api_key_here'
session_key = 'session_key_here'
session_secret = 'session_secret_here
last_update = 0
prev_items = nil
loop {
args = {'v'=>'1.0', 'format' => 'JSON', 'method' => 'fql.query',
'query' => "select post_id, created_time from stream where " +
"filter_key in " +
"(select filter_key FROM stream_filter where " +
"uid = 688626964 and type = 'newsfeed') and created_time >= " +
last_update.to_s + ' order by created_time desc limit 50',
'api_key' => api_key, 'session_key' => session_key,
'call_id' => Time.now.tv_sec,
'ss' => '1.0'}
hashString = args.keys.sort.map{|key|
"#{key}=#{args[key]}"}.push(session_secret).join
args['sig'] = Digest::MD5.hexdigest(hashString)
res = Net::HTTP.post_form(URI.parse('http://api.facebook.com/restserver.php'),
args)
items = res.body.to_s.delete('":[]').gsub('post_id',
'').gsub('created_time', '').split('},{').map {|item|
item.delete('{}').split(',')
}
last_update = items.last[1]
if (prev_items)
# Did we gain some?
gained = items.find_all { |item|
!prev_items.find{|prev_item| prev_item[0] == item[0] }
}
# Did we lose any
lost = prev_items.find_all { |prev_item|
!items.find{|item| prev_item[0] == item[0] }
}
# If gain is high, print it:
if (gained.length > 3)
puts "Gained: #{gained.map{|g| g[0]}.join(',')}"
end
# If lost is high, print it:
if (lost.length > 3)
puts "Lost: #{lost.map{|l| l[0]}.join(',')}"
end
end
prev_items = items
sleep 20
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment