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. [AngularJS] Transforming raw JSON data to meaningful output in AngularJS

    angular.module('APP', []) .controller('MainController', function($scope, UserConstants){ var user = ...

  2. FineUI表单验证

    自动编码文本 默认情况下,Label的EncodeText属性为true,会对文本中的HTML进行编码.当然我们也可以设置EncodeText=false,从而将HTML片段赋值给Text属性,请看这 ...

  3. AngularJs练习Demo10 ngInclude

    @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport&quo ...

  4. PowerDesigner使用常见问题

    1.在数据库生成表的时候,要求PowerDesigner中设计的表的Name的值要放到数据库中表的描述中,而不是PowerDesigner 中字段的Comment: 具体方法如下:首先将PowerDe ...

  5. Go学习笔记(二):编写 HelloWorld 程序

    //Hello.go代码 package main import "fmt" func main(){ fmt.Printf("Hello, world!This is ...

  6. ubuntu14.04中解压缩window中的zip文件,文件名乱码的解决方法

    在windows上压缩的文件,是以系统默认编码中文来压缩文件.由于zip文件中没有声明其编码,所以linux上的unzip一般以默认编码解压,中文文件名会出现乱码. 通过unzip行命令解压,指定字符 ...

  7. meta便签的用法

    1.定义编码规则,<meta http-equiv="Content-Type" content="text/html; charset=utf-8" / ...

  8. 转载:Struts2+Jquery实现ajax并返回json类型数据

    摘要: 主要实现步骤如下: 1.JSP页面使用脚本代码执行ajax请求 2.Action中查询出需要返回的数据,并转换为json类型模式数据 3.配置struts.xml文件 4.页面脚本接受并处理数 ...

  9. dobbo学习

    http://www.cnblogs.com/Javame/p/3632473.html 1. Dubbo是什么? Dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以 ...

  10. NSRunLoop 详解

    今天看到了NSRunloop,其实之前也有看了关于NSRunloop的内容,在这里想简单的就个人的理解总结一下.其实自己在开发的过程当中,还没有更多的涉及到NSRunloop的功能.总的来说,NSRu ...