Created
November 11, 2015 17:12
-
-
Save micmmakarov/c7733145cc3840deca9c to your computer and use it in GitHub Desktop.
Analyze person's likes to figure out who's the most active
This file contains hidden or 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
api_key = "https://developers.facebook.com/tools/explorer" | |
api = Koala::Facebook::API.new(api_key) | |
profile = api.get_object("me") | |
profile = _ | |
profile.keys | |
profile['birthday'] | |
feed = api.get_connections "me", "feed" | |
likes = feed.map do |f| | |
if f['likes'] | |
f['likes']['data'].map {|like| like['name']} | |
end | |
end.flatten | |
stats = {} | |
likes.each do |name| | |
if stats[name] | |
stats[name] += 1 | |
else | |
stats[name] = 1 | |
end | |
end | |
likes_array = stats.map {|key, value| {name: key, likes: value}} | |
likes_array.sort! {|a, b| b[:likes] <=> a[:likes]} | |
likes_array.each do |like| | |
puts "#{like[:name]}: #{like[:likes]}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment