forked from SocialLinks-IO/sociallinks-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathface_search_example.py
77 lines (65 loc) · 2.73 KB
/
face_search_example.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
import argparse
import os
import requests
from alive_progress import alive_bar
from concurrent.futures import ThreadPoolExecutor, as_completed
def make_request(domain, platform, name, photo_url, api_key):
base_url = f"https://{domain}/api/social_mapper/{platform}/v2"
params = {
'fullname': name,
'photo': photo_url,
'max_profiles': 300,
'only_first_equal': 1
}
headers = {
'Authorization': api_key
}
response = requests.get(base_url, headers=headers, params=params)
if response.status_code == 200:
json_data = response.json()
data = json_data.get('results', json_data.get('result', []))
result = [
(item['url'], item.get('title', item.get('name', f"{item.get('first_name')} {item.get('last_name')}"))) for
item in data]
return result
else:
return []
def search_profiles(domain, platforms, name, photo_url, api_key):
search_results = []
with ThreadPoolExecutor(max_workers=len(platforms)) as executor:
futures = {executor.submit(make_request, domain, platform, name, photo_url, api_key): platform for platform in
platforms}
with alive_bar(len(platforms), title="Searching profiles") as bar:
for future in as_completed(futures):
platform = futures[future]
try:
result = future.result()
if result:
search_results.extend(result)
except Exception as exc:
print(f"Exception for platform {platform}: {exc}")
bar()
return search_results
def parse_args():
parser = argparse.ArgumentParser(description='Search social media profiles based on name and photo.')
parser.add_argument('--platforms', type=str, required=True,
help='Comma-separated list of platforms to search (e.g. twitter,youtube,myspace)')
parser.add_argument('--name', type=str, required=True, help='Full name of the person to search for')
parser.add_argument('--photo_url', type=str, required=True, help='URL of the photo to use for search')
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
platforms = args.platforms.split(',')
name = args.name
photo_url = args.photo_url
domain = os.getenv('API_DOMAIN')
if not domain:
print("Error: Please set the API_DOMAIN environment variable.")
exit(1)
api_key = os.getenv('API_KEY')
if not api_key:
print("Error: Please set the API_KEY environment variable.")
exit(1)
results = search_profiles(domain, platforms, name, photo_url, api_key)
for url, name in results:
print(f"Name: {name}, URL: {url}")