CODE:

#!/usr/bin/python
# -*- coding: utf-8 -*- '''
Created on 2014-8-12
@author: guaguastd
@name: friends_popular_category.py
''' # impot login
from login import facebook_login # import helper
#from helper import pp # calculating the most popular category among your friends
from prettytable import PrettyTable
from collections import Counter # access to facebook
facebook_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 request
friends = 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:', likes friends_likes_categories = Counter([like['category']
for friend in likes
for like 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(10) ]
print 'Top 10 likes categories for friends'
print pt

RESULT:

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

Python 获取Facebook用户Friends的爱好类别中的Top10的更多相关文章

  1. Python 获取Facebook用户的Friends的爱好中的Top10

    CODE; #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-12 @author: guaguastd @name: f ...

  2. Python 统计Facebook用户爱好的个数

    CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-12 @author: guaguastd @name: f ...

  3. Python 获得Facebook用户有一个共同的兴趣Friends

    CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-13 @author: guaguastd @name: c ...

  4. Python 获取Twitter用户与Friends和Followers的关系(eg, 交集,差集)

    CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-30 @author: guaguastd @name: f ...

  5. python 获取mysql数据库列表以及用户权限

    一.需求分析 需要统计出当前数据库的所有数据库名,以及每个用户的授权信息. 获取所有数据库 在mysql里面,使用命令: show databases 就可以获取所有数据库了 获取所有用户 执行命令: ...

  6. python flask获取微信用户信息报404,nginx问题

    在学习flask与微信公众号时问题,发现测试自动回复/wechat8008时正常,而测试获取微信用户信息/wechat8008/index时出现404.查询资料后收发是nginx配置问题. 在loca ...

  7. Redis & Python/Django 简单用户登陆

    一.Redis key相关操作: 1.del key [key..] 删除一个或多个key,如果不存在则忽略 2.keys pattern keys模式匹配,符合glob风格通配符,glob风格的通配 ...

  8. Zabbix中获取各用户告警媒介分钟级统计

    任务内容: 获取Zabbix各用户告警媒介分钟级统计,形成趋势图,便于观察各用户在每分钟收到的告警数量,在后续处理中,可以根据用户在某时间段内(例如3分钟内)收到的邮件总数,来判断是否有告警洪水的现象 ...

  9. 用 Python 获取 B 站播放历史记录

    用 Python 获取 B 站播放历史记录 最近 B 站出了一个年度报告,统计用户一年当中在 B 站上观看视频的总时长和总个数.过去一年我居然在 B 站上看了2600+个视频,总计251个小时,居然花 ...

随机推荐

  1. 基于Hadoop的大数据平台实施记——整体架构设计[转]

    http://blog.csdn.net/jacktan/article/details/9200979 大数据的热度在持续的升温,继云计算之后大数据成为又一大众所追捧的新星.我们暂不去讨论大数据到底 ...

  2. 照猫画虎学gnuplot之简单介绍

    简单介绍:Gnuplot是一个命令行驱动的科学画图工具,可将数学函数或数值资料以平面图或立体图的形式画在不同种类终端机或画图输出装置上. 它是由Colin Kelley 和 Thomas Willia ...

  3. jquery之radio

    <td class="queryTitle" width="80px">是否启用</td> <td class="que ...

  4. 只包含schema的dll生成和引用方法

    工作中,所有的tools里有一个project是只包含若干个schema的工程,研究了一下,发现创建这种只包含schema的dll其实非常简单. 首先,在visual studio-new proje ...

  5. Javascript基础 函数“重载”

    Javascript不像其他编程语言一样具有函数签名(什么是函数签名,简单的说就是说函数的接受参数类型和参数个数,也有人认为返回类型也应该包括.具体概念大家可以到网上查询). 所以Javascript ...

  6. 查看kafka的group.id

    kafka/config目录下的consumer.properties中可以看到

  7. trailingZeroes

    Given an integer n, return the number of trailing zeroes in n!. 给一个数字n,返回它n!数字后面有多少个0. public class ...

  8. Sherlock and Squares

    //Link https://www.hackerrank.com/challenges/sherlock-and-squares from math import sqrt # 用什么,引什么,减少 ...

  9. IOS APP配置.plist汇总(转自coolweather )

    IOS APP配置.plist汇总(转自coolweather ) 此文转自http://www.cocoachina.com/bbs/read.php?tid=89684&page=1 作者 ...

  10. 养成代码注释习惯,帮助你更好使用NetBeans导航器

    在使用NetBeans编写php代码时,为了在一个类中,或者在方法库文件中快速找到你想要找的函数或方法,通常我们会使用NetBeans的导航器. 我们看一个导航器的事例: 大家知道,在php中代码习惯 ...