Skip to content

Instantly share code, notes, and snippets.

@emad-elsaid
Created March 20, 2014 12:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emad-elsaid/9662408 to your computer and use it in GitHub Desktop.
Save emad-elsaid/9662408 to your computer and use it in GitHub Desktop.
Facebook group hall of fame script
#!/usr/bin/env ruby
require 'koala' # gem install koala --no-document
require 'psych'
# create a facebook app and get access token from here
# https://developers.facebook.com/tools/explorer
# select "user_groups" when authenticating
oauth_access_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
group_name = 'Egyptian Geeks'
posts_limit = 100
graph = Koala::Facebook::API.new(oauth_access_token)
# getting groups of interest
group = graph.get_connections('me', 'groups').find { |g| g['name']==group_name }
raise Exception.new 'Group Not found' unless group
# get posts
posts = []
page = graph.get_connections(group['id'],'feed')
begin
posts += page
end while page = page.next_page and posts.length<=posts_limit
# generate analytics
analytics = posts.inject({}) do |mem, post|
if mem.keys.include? post['from']['name']
mem[post['from']['name']] += 1
else
mem[post['from']['name']] = 1
end
mem
end
# sort descending and convert each to key => value again
sorted = analytics.sort_by { |k,v| -v }.map {|k,v| {k => v}}
puts sorted.to_yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment