-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage_parser.py
More file actions
41 lines (40 loc) · 1.51 KB
/
message_parser.py
File metadata and controls
41 lines (40 loc) · 1.51 KB
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
import requests
import json
r = requests.get("https://graph.facebook.com/v2.3/186957608173966/comments?limit=25&__paging_token=enc_AdDROMkcRsTE08ZAeZAZC0goPHEgAdSiS2XuClMPBqiHdYXGUtILUCkwkTvST10QkWWtGejwZAgmKg2zZBvgVwpeuo2UZA&since=1483568411&__previous=1&access_token=EAACEdEose0cBAEocbeN4HW1NwQAqKiq3ci9wFZCSZB5oxg68tjZAQHPMnI91jZCzZB90YCqrHDZCjVa3OSJRxRicIzZAjG3H58OhKz4OjGZCUFKT9PQVJ4smQ1Num1Iuv0zfnx2I0R5iXnba4TwCCpJ0kslzyu2aehxtJwgt27hL9C4jZCUAvezEmHSluEmaGROMZD")
list_a = []
list_b = []
a_id = ""
b_id = ""
messages = json.loads(r.text)
for data in messages["data"]:
if "message" not in data.keys():
continue
if not list_a:
a_id = data["from"]["id"]
list_a.append(data["message"])
continue
if not b_id and a_id != data["from"]["id"]:
b_id = data["from"]["id"]
if data["from"]["id"] == a_id:
list_a.append(data["message"])
else:
list_b.append(data["message"])
for x in range(40):
r = requests.get(messages["paging"]["next"])
messages = json.loads(r.text)
for data in messages["data"]:
if "message" not in data.keys():
continue
if not list_a:
a_id = data["from"]["id"]
list_a.append(data["message"])
continue
if not b_id and a_id != data["from"]["id"]:
b_id = data["from"]["id"]
if data["from"]["id"] == a_id:
list_a.append(data["message"])
else:
list_b.append(data["message"])
print(list_a)
print("\n\n\n\n")
print(list_b)