Skip to content

Instantly share code, notes, and snippets.

@bholzer
Created October 29, 2014 01:33
Show Gist options
  • Save bholzer/1e4de84dac104b302dd2 to your computer and use it in GitHub Desktop.
Save bholzer/1e4de84dac104b302dd2 to your computer and use it in GitHub Desktop.
require 'koala'
graph = Koala::Facebook::API.new("redacted")
two_weeks_ago = Time.now - (2*7*24*60*60)
members = graph.get_object("355625917946909/members")
member_names = members.map{|mem| mem["name"]}
feed = graph.get_object("355625917946909/feed?fields=from,likes,link,comments.limit(10000000)&limit=10000000&since=#{two_weeks_ago.to_i}")
most_liked = feed.select{|post| !post["likes"].nil? }.sort {|a,b| b["likes"]["data"].size <=> a["likes"]["data"].size}
posters_in_last_two_weeks = feed.map {|post| post["from"]["name"] }.uniq
commenters_in_last_two_weeks = feed.select{|post| !post["comments"].nil?}
.map {|post| post["comments"]["data"] }
.flatten
.select {|comment| !comment["from"].nil? }
.map {|comment| comment["from"]["name"] }
.uniq
puts "Posters in the last two weeks: \n" + posters_in_last_two_weeks.sort.join("\n ")
puts "\n\nCommenters in the last two weeks: \n" + commenters_in_last_two_weeks.sort.join("\n ")
puts "\n\nHaven't commented or posted in two weeks: \n" + (member_names - (commenters_in_last_two_weeks + posters_in_last_two_weeks)).sort.join("\n ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment