CODE:

#!/usr/bin/python
# -*- coding: utf-8 -*- '''
Created on 2014-8-13
@author: guaguastd
@name: common_friends_finding.py
''' # impot login
from login import facebook_login # import helper
#from helper import pp # import PrettyTable
from prettytable import PrettyTable
from collections import Counter
from operator import itemgetter # 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]} friends_likes = Counter([like['name']
for friend in likes
for like in likes[friend]
if like.get('name')]) # Which of your likes are in common with which friends
my_likes = [ like['name']
for like in facebook_api.get_connections("me", "likes")['data'] ] # Use the set intersection as represented by the ampersand
# operator to find common likes
common_likes = list(set(my_likes) & set(friends_likes)) # Which of your friends like things that you like?
similar_friends = [ (friend, friend_like['name'])
for friend, friend_likes in likes.items()
for friend_like in friend_likes
if friend_like.get('name') in common_likes ] # Filter out any possible duplicates that could occur
ranked_friends = Counter([ friend for (friend, like) in list(set(similar_friends)) ]) pt = PrettyTable(field_names=["Friend", "Common Likes"])
pt.align["Friend"], pt.align["Common Likes"] = 'l', 'r'
[ pt.add_row(rf)
for rf in sorted(ranked_friends.items(),
key=itemgetter(1),
reverse=True)]
print "My similar friends (ranked)"
print pt

RESULT:

My similar friends (ranked)
+--------------------------+--------------+
| Friend | Common Likes |
+--------------------------+--------------+
| Los Mas Lindos del Mundo | 1 |
| Soofi Cat | 1 |
| Jorge Rodriguez | 1 |
| Kevin Swaggy | 1 |
+--------------------------+--------------+

Python 获得Facebook用户有一个共同的兴趣Friends的更多相关文章

  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用户爱好的个数

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

  4. python练习:编写一个程序,要求用户输入一个整数,然后输出两个整数root和pwr,满足0<pwr<6,并且root**pwr等于用户输入的整数。如果不存在这样一对整数,则输入一条消息进行说明。

    python练习:编写一个程序,要求用户输入一个整数,然后输出两个整数root和pwr,满足0<pwr<6,并且root**pwr等于用户输入的整数.如果不存在这样一对整数,则输入一条消息 ...

  5. Python之路,Day18 - 开发一个WEB聊天来撩妹吧

    Python之路,Day18 - 开发一个WEB聊天来撩妹吧   本节内容: 项目实战:开发一个WEB聊天室 功能需求: 用户可以与好友一对一聊天 可以搜索.添加某人为好友 用户可以搜索和添加群 每个 ...

  6. python 正则的使用 —— 编写一个简易的计算器

    在 Alex 的博客上看到的对正则这一章节作业是编写一个计算器,要求能计算出下面的算式. 1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 + ...

  7. Python 练习冊,每天一个小程序

    Python 练习冊,每天一个小程序 说明:     Github 原文地址: 点击打开链接 Python 练习冊.每天一个小程序.注:将 Python 换成其它语言,大多数题目也试用 不会出现诸如「 ...

  8. 第三百五十节,Python分布式爬虫打造搜索引擎Scrapy精讲—selenium模块是一个python操作浏览器软件的一个模块,可以实现js动态网页请求

    第三百五十节,Python分布式爬虫打造搜索引擎Scrapy精讲—selenium模块是一个python操作浏览器软件的一个模块,可以实现js动态网页请求 selenium模块 selenium模块为 ...

  9. 如何在unix系统中用别的用户运行一个程序?

    1.问题的缘由 实际开发系统的时候,经常需要用别的用户运行一个程序.比如,有些系统为保证系统安全,不允许使用root来运行.这里,我们总结了unix系统下如何解决这个问题的一些方法.同时,我们还讨论如 ...

随机推荐

  1. CrossBridge介绍

    CrossBridge介绍 作者:chszs,转载需注明.博客主页: http://blog.csdn.net/chszs CrossBridge是Adobe FlasCC的开源版本,它提供了一个完整 ...

  2. httl开源JAVA模板引擎,动态HTML页面输出

    HTTL(Hyper-Text Template Language)是一个适用于HTML输出的开源JAVA模板引擎,适用于动态HTML页面输出,可用于替代JSP页面,它的指令类似于Velocity. ...

  3. WPF界面设计技巧(5)—自定义列表项呈现内容

    原文:WPF界面设计技巧(5)-自定义列表项呈现内容 接续上次的程序,稍微改动一下原有样式,并添加一个数据模板,我们就可以达成下面这样的显示功能: 鼠标悬停于文件列表项上,会在工具提示中显示图像缩略图 ...

  4. Apache的Mesos和Google的Kubernetes 有什么区别?

    Apache的Mesos和Google的Kubernetes 有什么区别?本文来自StackOverFlow上的一个问题,主要讨论Mesos和Kubernetes的区别,相信我们很多人也有同意的疑问. ...

  5. angularjs入门学习【指令篇】

    一.首先我们来了解下指令API 属性 含义 restrict 申明标识符在模版中作为元素,属性,类,凝视或组合,怎样使用 priority 设置模版中相对于其它标识符的运行顺序 Template 指定 ...

  6. 数据库连接技术之OLE DB

    之前的博客介绍了ODBC和JDBC.这次简单的介绍一下OLE DB.ODBC的总结不知道是没贴到博客上还是不在这个博客上,我再找找,没有的话我再补充到时候.好了.開始吧. 回想 之前呢介绍过了ODBC ...

  7. android uiautomator自己主动化測试

    前提是自己电脑上配置好JDK,android和ant的环境 1.命令行下进入\Android-sdk\tools\文件夹下,执行命令:    android list    查看相应android版本 ...

  8. PyUnit框架学习

    http://www.oschina.net/question/12_27127#INSTALL http://www.360doc.com/content/11/0606/23/54470_1221 ...

  9. Spring Bean的作用域(转)

    Spring Bean的作用域 .singleton  [单例] eg:<bean id="personService" class="com.yinger.ser ...

  10. ZOJ--3631--Watashi&#39;s BG【枚举】

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4777 题意:有n天,告诉你每天的花费,别人给你一笔资金m,你自己也有一部 ...