Python gets Top10 from Facebook user Friends's hobby category

Source: Internet
Author: User

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 |+--------------------------+------+


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.