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

最新文章

  1. JDBC数据库访问操作的动态监测 之 Log4JDBC
  2. 联合体(union)的使用方法及其本质
  3. C#基础知识记录一
  4. windows 下用eclipse搭建java、python开发环境
  5. 移动端HTML5<video>视频播放优化实践[转]
  6. SQL语句优化原则
  7. psp开发------汉化插件
  8. Swipecards
  9. Git命令详解
  10. avalon.js 多级下拉框实现
  11. c++中多态性、dynamic_cast、父类指针、父类对象、子类指针、子类对象
  12. SSIS DB目录设置 (Integration Services Catalogs)
  13. 谈谈一些有趣的CSS题目(十四)-- 纯 CSS 方式实现 CSS 动画的暂停与播放!
  14. 堆排序(Java数组实现)
  15. Sublime Text3激活
  16. git(命令行常用炒作)
  17. 一筐鸡蛋的lcm
  18. JAVA-常用集合类型转换例子(基础必备)
  19. 如何使用queue_delayed_work函数
  20. 3.2Python的循环结构语句:

热门文章

  1. sqlyog使用注意事项
  2. window.location.href 和self.location的区别
  3. Android开发中在一个Activity中关闭另一个Activity
  4. java.io.FileNotFoundException: class path resource [bean/test/User.hbm.xml] cannot be opened because it does not exist
  5. [<DDGuessYouLIkeModel 0x7c99faf0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key star.
  6. UVa12304
  7. rpc和websocket的区别
  8. $(this).val()与this.value的区别?text()与html()的区别?
  9. BufferedOutputStream
  10. 转:窗口启用/禁用功能函数EnableWindow的使用