Created
October 29, 2014 01:33
-
-
Save bholzer/1e4de84dac104b302dd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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