Python gets Facebook user's friends hobby in the TOP10

Source: Internet
Author: User

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


Related Article

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.