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. 单服务器防护linux iptables脚本

    #!/bin/bashiptables -Fiptables -P INPUT DROPiptables -P OUTPUT ACCEPTiptables -P FORWARD DROP/sbin/i ...

  2. Android模拟器设置竖屏

    使用Android模拟器測试自己开发的程序时,有时候会发现屏幕为横屏显示,查看效果非常不方便. 这里记录了一种禁止横屏的方法. 在文件  Mainfest.xml 中,在须要禁止横屏的 activit ...

  3. maven中的java库

    /* *  *         <dependency>    <groupId>io.netty</groupId>    <artifactId>n ...

  4. mysql 开放的telnet

    两步开幕mysql远程连接 一个,登录mysql # mysql -uroot -p 两,配置远程连接 mysql > GRANT ALL PRIVILEGES ON *.* TO 'user1 ...

  5. ZOJ 3795 Grouping 求最长链序列露点拓扑

    意甲冠军:特定n积分.m向边条. 该点被划分成多个集合随机的每个集合,使得2问题的关键是无法访问(集合只能容纳一个点) 问至少需要被分成几个集合. 假设没有戒指,接着这个话题正在寻求产业链最长的一个有 ...

  6. ios日历视图实现日期输入

    在视图控制器上,触摸textfield,打开的不是虚拟键盘,也不是datepicker,也不要actionsheet,要一个类似html上的日历输入框. 这类控件有很多开源的,但目标不是我想要的.参考 ...

  7. Java的Log系统介绍和切换(转)

    Java的log系统比较繁杂.在这里梳理一下.本文只涉及log系统介绍和处理log系统之间的切换.不涉及如何配置和使用. 具体的log系统 Log4j:准确的说是log4j 1.x版.是之前使用最广泛 ...

  8. erlang shell表格数据对齐

    近期在erlang shell做一些測试,为了让測试结果数据显得更直观,想对齐须要打印的数据,做成像表格一样的效果. 開始的想法是在数据中插入tab. 当然,erlang也有对tab的支持,但实际效果 ...

  9. Form表单中的action路径问题

    今天刚接触web,在用jsp和servlet做一个简单的登陆的时候在Form表单action属性和method属性的一些问题:  我遇到的是Form表单提交到servelet处理时遇到的问题:  (1 ...

  10. 使用LabVIEWPC的制备

    使用LabVIEWPC的制备 1.下载.安装LabVIEW 如今,互联网搜索,你可以搜索出一大推LabVIEW下载并安装破解教程.因此,这里没有具体描述的.请自行百度~~.另外.提醒一下,下载LabV ...