Python 统计Facebook用户爱好的个数
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用户爱好的个数的更多相关文章
- Python 获取Facebook用户的Friends的爱好中的Top10
CODE; #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-12 @author: guaguastd @name: f ...
- Python 获取Facebook用户Friends的爱好类别中的Top10
CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-12 @author: guaguastd @name: f ...
- Python 获得Facebook用户有一个共同的兴趣Friends
CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-13 @author: guaguastd @name: c ...
- Python 统计文本中单词的个数
1.读文件,通过正则匹配 def statisticWord(): line_number = 0 words_dict = {} with open (r'D:\test\test.txt',enc ...
- python 统计文件的个数
import os path = r'F:\1back\picture' #获取当前路径 count = 0 for root,dirs,files in os.walk(path): #遍历统计 i ...
- 揭秘Keras推荐系统如何建立模型、获取用户爱好
你是否有过这样的经历?当你在亚马逊商城浏览一些书籍,或者购买过一些书籍后,你的偏好就会被系统学到,系统会基于一些假设为你推荐相关书目.为什么系统会知道,在这背后又藏着哪些秘密呢? 荐系统可以从百万甚至 ...
- 用HttpSessionListener统计在线用户或做账号在线人数管理
使用HttpSessionListener接口可监听session的创建和失效 session是在用户第一次访问页面时创建 在session超时或调用request.getSession().inva ...
- python 统计使用技巧
python 统计使用技巧 # 1.不输入回车获取值 注:需要tty模块配合. fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) ...
- 如何用Python统计《论语》中每个字的出现次数?10行代码搞定--用计算机学国学
编者按: 上学时听过山师王志民先生一场讲座,说每个人不论干什么,都应该学习国学(原谅我学了计算机专业)!王先生讲得很是吸引我这个工科男,可能比我的后来的那些同学听课还要认真些,当然一方面是兴趣.一方面 ...
随机推荐
- leetcode - Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...
- [POJ 3735] Training little cats (结构矩阵、矩阵高速功率)
Training little cats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9613 Accepted: 2 ...
- 新 Netflix 开源门户
Netflix 开源改革计划:新 Netflix 开源门户 http://www.oschina.net/news/67555/evolution-of-open-source-at-netflix ...
- 蚁群算法 matlab程序(已执行)
下面是解放军信息project大学一个老师编的matlab程序,请尊重原作者劳动,引用时请注明出处. 我经过改动添加了凝视,已经执行过,无误, function [R_best,L_best,L_av ...
- Velocity缓存与穿透(转)
原文 http://fantaxy025025.iteye.com/blog/2283904 主题 Java 总评:只是标记一下这种用法hack方法.这种场景下用这种方法还是比较雷人的. Veloc ...
- Java--调试--单步调试,断言,单元测试
单步调试:主要查看变量内容的变化 1.设置断点位置,设置在可能出现问题的代码 2.以Debug as方式运行 程序 3.F5 --> step into 进入方法内部进行调试 F6 ...
- Setup Git Server in CentOS 6.3
0. Environment: Server machine: CentOS 6.3 x86 Client machine: Windows 10 Pro x86_64 1. Install ssh ...
- 采用大杀招QEMU调试Linux内核代码
Linux调试内核代码是非常麻烦.它们一般加printk, 或者使用JTAG调试. 这里的方法是使用QEMU为了调试Linux核心. 由于QEMU自己实现gdb server, 它可以容易地使用gdb ...
- Galaxy (hdu 5073 数学)
Galaxy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total S ...
- 什么是比特币(Bitcoin)?
比特币是一种类型的电子货币.点对点(P2P)网络跟踪和验证交易.比特币系统不涉及金融机构,因此它不需要中央监控单元以控制该货币.它可以利用网络作为现金. 比特币系统 比特币是在处理称为区块(block ...