Python counts the number of Facebook users ' hobbies

Source: Internet
Author: User

CODE:

#!/usr/bin/python #-*-Coding:utf-8-*-' Created on 2014-8-12@author:guaguastd@name:friends_likes_number.py ' ' # Impot loginfrom Login Import facebook_login# Import helper#from Helper import pp# import itemgetter from operator import I temgetter# Import prettytablefrom prettytable import prettytable# access to Facebookfacebook_api = Facebook_login () # get F Riends 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[:20]}print ' likes: ', likes# calculate the number of Likenum_likes_by_friend = {Friend:len (Likes[friend]) For friend in likes}pt = prettytable (field_names=[' friend ', ' Num likes ') pt.align[' friend '], Pt.alig n[' Num likes '] = ' l ', ' R ' [Pt.add_row (NLBF)   For nlbf in Sorted (Num_likes_by_friend.items (), Key=itemgetter (1), reverse=true )]print "Number of likes per friend" Print PT

RESULT:

Number of likes per friend+--------------------------+-----------+| Friend                   | Num likes |+--------------------------+-----------+| Ayelén Basualdo          |        25 | | Soofi Cat                |        25 | | Brenda Magali            |        25 | | Brisa Agustina?       |        25 | | Jeniifer Mendez          |        25 | | Wanda Bianchi            |        25 | | Los Mas Lindos del Mundo |        15 | | Kevin Swaggy             |        14 | | Jorge Rodriguez          |        11 | | Karen CSR                |         8 | | Silvia Dutto             |         3 | | Nanu Soria               |         3 | | Wucheng                     |         1 |+--------------------------+-----------+


Python counts the number of Facebook users ' hobbies

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.