-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathcount.py
28 lines (24 loc) · 886 Bytes
/
count.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
import requests,time
#add your toke here
token = ''
payload = {'method': 'GET','fields': 'message_count,senders,thread_key', 'access_token':token}
t = requests.get('https://graph.facebook.com/v2.10/me/conversations', params=payload).json()
data = {}
data['data'] = []
while True:
try:
for i in t['data']:
if i["thread_key"][0:5] == "t_100":
name = i["senders"]["data"][0]['name']
number_count = i['message_count']
name_and_count = {'name': name, 'number_count': number_count}
data['data'].append(name_and_count)
t=requests.get(t["paging"]["next"]).json()
except KeyError:
break
data = sorted(data['data'], key=lambda k: k['number_count'], reverse=True)
print 'top 20'
i = 0
while i < 20:
print '%s => %u mess' %(data[i]['name'], data[i]['number_count'])
i +=1