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 |
+--------------------------+-----------+
时间: 2024-10-07 19:19:00

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

Python 获取Facebook用户的Friends的爱好

Code: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-11 @author: guaguastd @name: friends_like_query.py ''' # impot login from login import facebook_login # import helper from helper import pp # access to facebook facebook_api = face

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 prettytab

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

CODE; #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-12 @author: guaguastd @name: friends_popular_likes.py ''' # impot login from login import facebook_login # import helper from helper import pp # calculating the most popular likes

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

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-12 @author: guaguastd @name: friends_popular_category.py ''' # impot login from login import facebook_login # import helper #from helper import pp # calculating the most popular ca

Python 对Facebook用户Friendship的聚类分析

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-13 @author: guaguastd @name: friendship_graph_construct.py ''' import networkx as nx import requests import json ACCESS_TOKEN = '' # impot login from login import facebook_login #

oracle统计某个用户的对象个数

--统计某个用户下面的对象个数 --包括表,视图,同义词,函数,存储过程,包,触发器,索引,约束,序列. SELECT (SELECT COUNT(*) FROM USER_TABLES) AS TABLES, (SELECT COUNT(*) FROM USER_VIEWS)AS VIEWS, (SELECT COUNT(*) FROM USER_SYNONYMS)AS SYNONYMS, (SELECT COUNT(*) FROM USER_OBJECTS WHERE OBJECT_TYPE

sql和python统计ip(用户)当天充值总额

sql查询当天的充值记录导入 sql code --查询当天的数据 select * from a where generateTime=sysdate --查询一个星期的数据 select * from a where (sysdate-generaeTime)=7 --查询一个月的数据 select * from a where months_between(sysdate,generateTime)=1  --查询某一天的数据 select * from table where col b

Python 获取Facebook特定用户的粉丝数

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-9 @author: guaguastd @name: fan_pages_compare.py ''' # impot login from login import facebook_login # import helper from helper import pp, int_format # access to facebook facebook_

Python 获取Facebook特定用户的feed和link

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-9 @author: guaguastd @name: facebook_connection_query.py ''' # impot login from login import facebook_login # import helper from helper import pp # access to facebook facebook_api