Python 获得Facebook用户有一个共同的兴趣Friends
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的更多相关文章
- 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用户爱好的个数
CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-12 @author: guaguastd @name: f ...
- python练习:编写一个程序,要求用户输入一个整数,然后输出两个整数root和pwr,满足0<pwr<6,并且root**pwr等于用户输入的整数。如果不存在这样一对整数,则输入一条消息进行说明。
python练习:编写一个程序,要求用户输入一个整数,然后输出两个整数root和pwr,满足0<pwr<6,并且root**pwr等于用户输入的整数.如果不存在这样一对整数,则输入一条消息 ...
- Python之路,Day18 - 开发一个WEB聊天来撩妹吧
Python之路,Day18 - 开发一个WEB聊天来撩妹吧 本节内容: 项目实战:开发一个WEB聊天室 功能需求: 用户可以与好友一对一聊天 可以搜索.添加某人为好友 用户可以搜索和添加群 每个 ...
- python 正则的使用 —— 编写一个简易的计算器
在 Alex 的博客上看到的对正则这一章节作业是编写一个计算器,要求能计算出下面的算式. 1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 + ...
- Python 练习冊,每天一个小程序
Python 练习冊,每天一个小程序 说明: Github 原文地址: 点击打开链接 Python 练习冊.每天一个小程序.注:将 Python 换成其它语言,大多数题目也试用 不会出现诸如「 ...
- 第三百五十节,Python分布式爬虫打造搜索引擎Scrapy精讲—selenium模块是一个python操作浏览器软件的一个模块,可以实现js动态网页请求
第三百五十节,Python分布式爬虫打造搜索引擎Scrapy精讲—selenium模块是一个python操作浏览器软件的一个模块,可以实现js动态网页请求 selenium模块 selenium模块为 ...
- 如何在unix系统中用别的用户运行一个程序?
1.问题的缘由 实际开发系统的时候,经常需要用别的用户运行一个程序.比如,有些系统为保证系统安全,不允许使用root来运行.这里,我们总结了unix系统下如何解决这个问题的一些方法.同时,我们还讨论如 ...
随机推荐
- 求1e11以内的素数
有两种做法,一种是打表,另一种是直接求. 打表 将1e11每隔len(len=2000w)个数字统计一下该区间内素数的个数,比如cnt[1] 表示[1,len]以内有多少个素数,cnt[2]表示[le ...
- httpcomponents-client-ga(4.5)
http://hc.apache.org/httpcomponents-client-ga/tutorial/html/ Chapter 1. Fundamentals Prev Next ...
- C++ 在字符串中插入子串+推断字符串是否由空格组成
// Example3.cpp : 定义控制台应用程序的入口点. #include "StdAfx.h" #include <string> #include < ...
- 用标准Struts2+mvc写的用户管理
这星期的实验,最终调好了. 一句话,麻雀虽小,五脏俱全.相信刚学struts2的同学能够通过该实验能够更好地理解struts的结构和mvc 登录的之前写过,这里直接进入用户管理 用struts2都要在 ...
- Html5 Device API详解
三.四月曾学习过html5相关知识,并就html5 device api做过一次讲解 课程时长一个小时,预期达到level 200目标,即知道html5 device api是什么,且知道怎么实现 面 ...
- 黄聪:Microsoft Enterprise Library 5.0 系列教程(三) Validation Application Block (高级)
原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(三) Validation Application Block (高级) 企业库验证应用程序模块之配置文件模式: ...
- windows phone (25) Canvas元素B
原文:windows phone (25) Canvas元素B ZIndex 这也是一个附加属性,表示canvas的children集合内的子元素的显示顺序,在canvas中的元素默认情况下是后面的 ...
- NYOJ 45 棋盘覆盖 模拟+高精度
题意就不说了,中文题... 小白上讲了棋盘覆盖,于是我就挖了这题来做. 棋盘覆盖的推导不是很难理解,就是分治的思想,具体可以去谷歌下. 公式就是f(k) = f(k - 1) * 4 + 1,再化解下 ...
- C#中使用gRPC
C#中使用gRPC 我的这几篇文章都是使用gRPC的example,不是直接编译example,而是新建一个项目,从添加依赖,编译example代码,执行example.这样做可以为我们创建自己的项目 ...
- 【原创】leetCodeOj --- Binary Search Tree Iterator 解题报告
时间挤挤总是有的 太久不做题,脑子都生锈了.来道水题练练手 题目地址: https://leetcode.com/problems/binary-search-tree-iterator/ 题目内容: ...