-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtruecaller_api.py
More file actions
42 lines (37 loc) · 2.03 KB
/
Copy pathtruecaller_api.py
File metadata and controls
42 lines (37 loc) · 2.03 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
42
import sys
import json
import urllib.parse
import requests
def search_number(phone_number):
# Encode the phone number
number = urllib.parse.quote(phone_number)
# Headers
headers = {
'User-Agent': 'Mozilla/5.0 (Linux; Android 12; CPH2269 Build/SP1A.210812.016) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.128 Mobile Safari/537.36 XiaoMi/Mint Browser/3.9.3',
'Accept-Encoding': 'gzip, deflate, br, zstd',
'sec-ch-ua-platform': '"Android"',
'authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NjQzMzAyODA4NDksInRva2VuIjoiYTF3MEUtLXVpbmpYLWt0RnQwdUFJZUM4ckp2am10QVhpLTFsMlc3Zy1NbnlORUF0OXluQ2RWZ1ZDN3dCR2ZGdiIsImNvdW50cnlDb2RlIjoiYmQiLCJuYW1lIjoiTUQgU0lIQUIgQ0hPV0RIVVJZIiwiaW1hZ2UiOiJodHRwczovL2ltYWdlcy1ub25ldS50cnVlY2FsbGVyc3RhdGljLmNvbS9teXZpZXcvMi82OTc4NzU3YTNkMzk0ZTZkNWM3MGE5MTFhYjYyNTgzYS8zIiwiaXNBcHBBY2NvdW50Ijp0cnVlLCJpYXQiOjE3NjE2NTE4ODB9.iXGswiGcV0FTSpnFJEKAWbSmSGXSgGcMwz3ZNKuKo2g',
'origin': 'https://www.truecaller.com',
'x-requested-with': 'com.mi.globalbrowser.mini',
'referer': 'https://www.truecaller.com/',
'accept-language': 'en-BD,en;q=0.9,bn-BD;q=0.8,bn;q=0.7,en-US;q=0.6'
}
# Make the request
try:
url = f"https://asia-south1-truecaller-web.cloudfunctions.net/webapi/noneu/search/v2?q={number}&countryCode=bd&type=44"
response = requests.get(url, headers=headers, timeout=30)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
return {"error": str(e)}
if __name__ == "__main__":
if len(sys.argv) > 1:
phone_number = sys.argv[1]
else:
phone_number = input("Enter phone number (with country code): ").strip()
if not phone_number:
print(json.dumps({"error": "No phone number provided"}, indent=2))
sys.exit(1)
result = search_number(phone_number)
# Ensure proper Unicode handling when printing
print(json.dumps(result, indent=2, ensure_ascii=False))