Python 获取Facebook用户的Friends的爱好中的Top10
2024-08-25 01:38:52
CODE;
#!/usr/bin/python
# -*- coding: utf-8 -*- '''
Created on 2014-8-12
@author: guaguastd
@name: friends_popular_likes.py
''' # impot login
from login import facebook_login # import helper
from helper import pp # calculating the most popular likes 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:'
pp(likes) friends_likes = Counter([like['name']
for friend in likes
for like 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(10) ]
print '\rTop 10 likes amongst friends'
print pt
RESULT:
Top 10 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 |
+-------------------------------------------------------------+------+
最新文章
- JDBC数据库访问操作的动态监测 之 Log4JDBC
- 联合体(union)的使用方法及其本质
- C#基础知识记录一
- windows 下用eclipse搭建java、python开发环境
- 移动端HTML5<;video>;视频播放优化实践[转]
- SQL语句优化原则
- psp开发------汉化插件
- Swipecards
- Git命令详解
- avalon.js 多级下拉框实现
- c++中多态性、dynamic_cast、父类指针、父类对象、子类指针、子类对象
- SSIS DB目录设置 (Integration Services Catalogs)
- 谈谈一些有趣的CSS题目(十四)-- 纯 CSS 方式实现 CSS 动画的暂停与播放!
- 堆排序(Java数组实现)
- Sublime Text3激活
- git(命令行常用炒作)
- 一筐鸡蛋的lcm
- JAVA-常用集合类型转换例子(基础必备)
- 如何使用queue_delayed_work函数
- 3.2Python的循环结构语句:
热门文章
- sqlyog使用注意事项
- window.location.href 和self.location的区别
- Android开发中在一个Activity中关闭另一个Activity
- java.io.FileNotFoundException: class path resource [bean/test/User.hbm.xml] cannot be opened because it does not exist
- [<;DDGuessYouLIkeModel 0x7c99faf0>; setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key star.
- UVa12304
- rpc和websocket的区别
- $(this).val()与this.value的区别?text()与html()的区别?
- BufferedOutputStream
- 转:窗口启用/禁用功能函数EnableWindow的使用