-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
124 lines (103 loc) · 4.27 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import requests
import json
import base64
import argparse
import random
from localuseragent import ua
import csv
def settings():
""" Configuraion and settings """
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--id", help="Facebook UserID Account", required=True)
args = parser.parse_args()
userid = args.id
typeoflinks = int(input("1 for friends, 2 for followers, 3 for followings, 4 for hometown, 5 for current city, 6 for recent friendship, 7 for friend of high school\n==>")) -1
app_collection = ["2","32","33", "125", "124", '1', "54"]
b64req = "app_collection:"+str(userid)+":2356318349:"+str(app_collection[typeoflinks])
encodedBytes = base64.b64encode(b64req.encode("utf-8"))
encodedStr = str(encodedBytes, "utf-8")
return(encodedStr, userid)
def extractfriends(data, friends, cursor):
""" Extract Friends from each new pages. """
cursorplace = len(data['data']['node']['pageItems']['edges'])
if cursorplace != 0:
newcursor = data['data']['node']['pageItems']['edges'][cursorplace-1]['cursor']
else:
if cursor == 0:
print("No friends found")
exit()
newcursor = cursor
if newcursor != cursor:
if len(data['data']['node']['pageItems']['edges']) != 1:
for edge in data['data']['node']['pageItems']['edges']:
friends.append({
'name' : edge['node']['title']['text'],
'userid': edge["node"]['node']['id'],
'url_profile' : edge['node']['url'],
'picture_profile' : edge['node']['image']['uri'],
'informations':edge['node']['image']['uri']
})
else:
if cursor == 0:
print("No friends found")
exit()
newcursor = "end"
return (friends, newcursor)
def all_list(cursor, encodedStr, headers, friends):
""" Callback the same function with the new cursor."""
while cursor != "end":
payload = {
"av":'0',
'__user':'0',
'__a':'1',
'fb_api_req_friendly_name': 'ProfileCometAppCollectionListRendererPaginationQuery',
'variables': '{"count":8,"cursor":"'+str(cursor)+'",'+'"scale":1,"search":null,"id":"'+str(encodedStr)+'"}',
'server_timestamps': 'true',
'doc_id': '5225908510806517',
}
response = requests.post('https://www.facebook.com/api/graphql', headers=headers, data=payload)
data = response.json()
friends, cursor = extractfriends(data, friends, cursor)
return(friends)
def show_friends(friends, userid):
""" Read in the csv files and show the informations found. """
with open(f"{userid}.csv", 'w') as f:
writer= csv.writer(f)
writer.writerow(['name', 'userid', 'url_profile', 'picture_profile', 'informations'])
for friend in friends:
writer.writerow(friend.values())
print(friend['name'], friend['userid'])
def main():
headers = {
'User-Agent': random.choice(ua["browsers"]["chrome"]),
'Accept': '*/*',
'Accept-Language': 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3',
'X-FB-Friendly-Name': 'ProfileCometAppCollectionListRendererPaginationQuery',
'Origin': 'https://www.facebook.com',
'DNT': '1',
'Connection': 'keep-alive',
'Sec-Fetch-Site': 'same-origin',
}
encodedStr, userid = settings()
data = {
'av': '0',
'__user': '0',
'fb_api_req_friendly_name': 'ProfileCometAppCollectionListRendererPaginationQuery',
'variables': '{"count":8,"scale":1,"search":null,"id":"'+str(encodedStr)+'"}',
'server_timestamps': 'true',
'doc_id': '5225908510806517',
}
response = requests.post('https://www.facebook.com/api/graphql/',headers=headers, data=data)
data = response.json()
if "errors" in data.keys():
print("Rate Limit")
exit()
if len(data['data']['node']['pageItems']['edges']) == 0:
print("These profile doesn't exist or doesn't have public friends list profile")
exit()
friends = list()
cursor = ""
friends, cursor = extractfriends(data, friends, cursor)
friends = all_list(cursor, encodedStr, headers, friends)
show_friends(friends, userid)
main()