CODE:

#!/usr/bin/python
# -*- coding: utf-8 -*- '''
Created on 2014-8-12
@author: guaguastd
@name: friends_likes_number.py
''' # impot login
from login import facebook_login # import helper
#from helper import pp # import itemgetter
from operator import itemgetter # import PrettyTable
from prettytable import PrettyTable # 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[:20]}
print 'likes:', likes # calculate the number of like
num_likes_by_friend = { friend : len(likes[friend])
for friend in likes } pt = PrettyTable(field_names=['Friend', 'Num Likes'])
pt.align['Friend'], pt.align['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 ʚiɞ | 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 |
| 吴城 | 1 |
+--------------------------+-----------+

Python 统计Facebook用户爱好的个数的更多相关文章

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

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

  2. Python 获取Facebook用户Friends的爱好类别中的Top10

    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 统计文本中单词的个数

    1.读文件,通过正则匹配 def statisticWord(): line_number = 0 words_dict = {} with open (r'D:\test\test.txt',enc ...

  5. python 统计文件的个数

    import os path = r'F:\1back\picture' #获取当前路径 count = 0 for root,dirs,files in os.walk(path): #遍历统计 i ...

  6. 揭秘Keras推荐系统如何建立模型、获取用户爱好

    你是否有过这样的经历?当你在亚马逊商城浏览一些书籍,或者购买过一些书籍后,你的偏好就会被系统学到,系统会基于一些假设为你推荐相关书目.为什么系统会知道,在这背后又藏着哪些秘密呢? 荐系统可以从百万甚至 ...

  7. 用HttpSessionListener统计在线用户或做账号在线人数管理

    使用HttpSessionListener接口可监听session的创建和失效 session是在用户第一次访问页面时创建 在session超时或调用request.getSession().inva ...

  8. python 统计使用技巧

    python 统计使用技巧 # 1.不输入回车获取值 注:需要tty模块配合. fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) ...

  9. 如何用Python统计《论语》中每个字的出现次数?10行代码搞定--用计算机学国学

    编者按: 上学时听过山师王志民先生一场讲座,说每个人不论干什么,都应该学习国学(原谅我学了计算机专业)!王先生讲得很是吸引我这个工科男,可能比我的后来的那些同学听课还要认真些,当然一方面是兴趣.一方面 ...

随机推荐

  1. extjs_11_mvc模式

    1.非mvc模式 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYWRhbV93enM=/font/5a6L5L2T/fontsize/400/fill/I ...

  2. ConcurrentHashMap中的2的n次方幂上舍入方法(转)

    最近看JDK中的concurrentHashMap类的源码,其中有那么一个函数: /** * Returns a power of two table size for the given desir ...

  3. Cantor的数表 【找规律】

    小俞同学,近期勤学苦练数学,对一种数表产生了兴趣. 数表例如以下: 1/1 1/2 1/3 1/4 1/5 2/1 2/2 2/3 2/4 3/1 3/2 3/3 4/1 4/2 5/1 她冥思苦相了 ...

  4. 【JAVA学习】“-Xmx1024m -Xms1024m -Xmn512m -Xss256k”——Java执行參数(转)

    年轻代 年老代概念 http://jefferent.iteye.com/blog/1123677 JVM的堆的内存, 是通过以下面两个參数控制的  -Xms 最小堆的大小, 也就是当你的虚拟机启动后 ...

  5. <EditText /> This text field does not specify an inputType or a hint

    我是一个警告,xml代码是: <EditText android:id="@+id/str_ipaddress" android:layout_width="wra ...

  6. Linux查看进程线程个数

    1.根据进程号进行查询: # pstree -p 进程号 # top -Hp 进程号 2.根据进程名字进行查询: # pstree -p `ps -e | grep server | awk '{pr ...

  7. Unity3D之挥动武器产生的剑痕特效

    网维教程网 观看很多其它教程 眼下已知3种方法能够做这样的剑痕特效 1.尾随特效 2.程序实现动态面来处理剑痕动画. 3.美术实现剑痕动画,直接坐在模型动画里面 (由于我不会美术所以这个忽略 嘿嘿) ...

  8. Python学习入门基础教程(learning Python)--3.1Python的if分支语句

    本节研究一下if分支语句. if分支语句是Python下逻辑条件控制语句,用于条件执行某些语句的控制操作,当if后的条件conditon满足时,if其下的语句块被执行,但当if的控制条件condito ...

  9. DRY

    DRY(Don't Repeat Yourself )原则   凡是写过一些代码的程序猿都能够意识到应该避免重复的代码和逻辑.我们通过提取方法,提取抽象类等等措施来达到这一目的.我们总能时不时的听到类 ...

  10. lucas定理解决大组合数取模

    LL MyPow(LL a, LL b) { LL ret = ; while (b) { ) ret = ret * a % MOD; a = a * a % MOD; b >>= ; ...