CODE;
#!/usr/bin/python #-*-Coding:utf-8-*-' Created on 2014-8-12@author:guaguastd@name:friends_popular_likes.py ' ' # Impot loginfrom Login Import facebook_login# Import helperfrom Helper Import pp# calculating the most popular likes among Your friendsfrom prettytable import prettytablefrom Collections import counter# access to Facebookfacebook_api = Facebook_ Login () # Get friends like through single request#friends_like = Facebook_api.get_object (' Me ', fields= ' Id,name, Friends.fields (id,name,likes) ') #pp (friends_like) # Get friends like through multi requestfriends = facebook_api.get_ Connections ("Me", "Friends") [' data ']likes = {friend[' name ']: facebook_api.get_connections (friend[' id '], "likes") [' Data '] for friend in Friends[:10]}print ' Likes: ' pp (likes) friends_likes = Counter ([like[' name '] For-friend in likes-in likes[friend] if Like.get (' name ' )]) pt = prettytable (field_names = [' Name ', ' Freq ']) pt. align[' Name '], pt.align[' Freq '] = ' l ', ' R ' [Pt.add_row (FL) for FL in Friends_likes.most_common (TEN)]print ' \rtop ' likes Amongst Friends ' Print PT
RESULT:
Top Ten likes amongst friends+-------------------------------------------------------------+------+| Name | Freq |+-------------------------------------------------------------+------+| BOCA | 2 | | Justin Bieber | 2 | | Casi Justicia Social | 2 | | Boca Juniors | 2 | | Retrica | 2 | | Mil Maneras de Decirle sutilmente a alguien que no te gusta | 1 | | Chicas lesbianas en busca de su Media naranja | 1 | | Willian Levy | 1 | | La Gente Anda Diciendo | 1 | | El Diario De Una Chica Rara | 1 |+-------------------------------------------------------------+------+