-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget_fb_names.py
48 lines (40 loc) · 1.66 KB
/
get_fb_names.py
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
"""
This file is part of The-Spyder-Girl.
The-Spyder-Girl is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The-Spyder-Girl is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with The-Spyder-Girl. If not, see <http://www.gnu.org/licenses/>.
"""
import facebook
from os import environ
import requests
# connect to facebook
graph = facebook.GraphAPI(access_token=environ['FACEBOOK_ACCESS_TOKEN'], version='2.7')
# download notifications and likes from facebook.
data = graph.get_object(id="me", fields="feed{likes{id,name}},notifications{from}")
def get_feed_names():
# create a empty dictionary
global data
data_feed = data['feed']
names = {}
while(True):
try:
# iterate the feed posts
for feed in data_feed['data']:
# iterate over likes on each post
if 'likes' in feed:
for like in feed['likes']['data']:
if like['name'] not in names:
names[like['name']] = 1
else:
names[like['name']] += 1
data_feed = requests.get(data_feed['paging']['next']).json()
except KeyError:
break
return names