forked from kapilkchaurasia/Data-mining-python-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
facebook_mining
65 lines (45 loc) · 1.78 KB
/
facebook_mining
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import requests # pip install requests
import json
import facebook
from prettytable import PrettyTable
from collections import Counter
#INPUT YOUR ACCESS_TOKEN
ACCESS_TOKEN = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXbdpJDBhVEaZA64pJRVUFLscZCZA9tlbIZAmgWfPy0bOziitZAyztqmTZBsay7'
base_url = 'https://graph.facebook.com/me'
g = facebook.GraphAPI(ACCESS_TOKEN)
#PRINTING YOUR FRIEND ALL "favorite_teams"
fs = g.get_object("me/friends")
for f in fs['data']:
#print f
#print f['name'],f['id']
print f['name']
for x in g.get_object(f['id'])['favorite_teams']:
print x['name']
#SEACHING TOP 10 PAGE ON INPUTTING PAGE NAME AND OUTPUT AS PAGE ID OF FACEBOOK
x= g.request('search', {'q' : 'pepsi', 'type' : 'page', 'limit' : 10})['data'][0]['id']
#GET ALL STATUS POST ON PARTICULAR PAGE(X=PAGE ID)
for x1 in g.get_connections(x, 'feed')['data']:
print x1
for x2 in x1:
print x2
if(x2['type']=='status'):
x2['message']
# Analyze all likes from friendships for frequency
friends_likes = Counter([like['name']
for friend in likes
for like in likes[friend]
if like.get('name')])
pt = PrettyTable(field_names=['Name', 'Freq'])
pt.align['Name'], pt.align['Freq'] = 'l', 'r'
[ pt.add_row(fl) for fl in friends_likes.most_common(10) ]
print 'Top 10 likes amongst friends'
print pt
# Analyze all like categories by frequency
friends_likes_categories = Counter([like['category']
for friend in likes
for like in likes[friend]])
pt = PrettyTable(field_names=['Category', 'Freq'])
pt.align['Category'], pt.align['Freq'] = 'l', 'r'
[ pt.add_row(flc) for flc in friends_likes_categories.most_common(10) ]
print "Top 10 like categories for friends"
print pt