CODE:
#!/usr/bin/python #-*-Coding:utf-8-*-"Created on 2014-8-12@author:guaguastd@name:friends_popular_category.py" # impot loginfrom Login Import facebook_login# Import helper#from Helper Import pp# Calculating the most popular category Among your friendsfrom prettytable import prettytablefrom Collections import counter# access to FACEBOOKFACEBOOK_API = FAC Ebook_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: ', likesfriends_likes_categories = Counter ([like[' category '] For-friend in likes-in Likes[friend]]) pt = prettytable (Field_names = [ ' Category ', ' Freq ']) pt.align[' category ', PT.Align[' Freq ' = ' l ', ' R ' [Pt.add_row (FLC) for FLC in Friends_likes_categories.most_common (Ten)]print ' Top ten likes Categori Es for friends ' Print PT
RESULT:
Top likes categories for friends+--------------------------+------+| Category | Freq |+--------------------------+------+| Community | 47 | | Musician/band | 34 | | Professional Sports Team | 10 | | Artist | 8 | | Public Figure | 5 | | Athlete | 5 | | Movie | 4 | | Local Business | 4 | | Actor/director | 4 | | APP Page | 4 |+--------------------------+------+