-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
120 lines (94 loc) · 3.36 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
import json
import flet as ft
import httpx
# IMPORTANT: Change this to your own token
auth_token = "YOUR_TOKEN_HERE"
async def get_number_info(number: str):
headers = {
'Host': 'search5-noneu.truecaller.com',
'Connection': 'keep-alive',
'Accept': '*/*',
'User-Agent': 'Truecaller/12.38.7 (com.truesoftware.TrueCallerOther; build:12.38.7; iOS 16.0.3) Alamofire/5.5.0',
'Accept-Language': 'en;q=1.0, ckb-US;q=0.9',
'Authorization': f'Bearer {auth_token}',
}
params = {
"countryCode": "iq",
"q": number,
"type": "4",
}
url = "https://search5-noneu.truecaller.com/v2/search"
async with httpx.AsyncClient() as client:
response = await client.get(url, headers=headers, params=params)
if response.status_code != 200:
return None
response_json = response.json()
data = response_json["data"][0] if len(response_json["data"]) > 0 else None
if data is None:
return None
if 'name' not in data:
return None
return {
"name": data["name"],
"score": data["score"],
}
class KurdishCaller(ft.UserControl):
def __init__(self):
self.container = None
self.ring = None
self.results = None
self.textfield = None
def build(self):
self.textfield = ft.TextField(hint_text="بە دوای ژمارەیەکدا بگەڕێ...", expand=True, )
self.results = ft.Column()
self.ring = ft.ProgressRing(visible=False)
self.container = ft.Container(self.ring, alignment=ft.alignment.center, padding=5)
return ft.Column(
width=600,
controls=[
ft.Row(
controls=[
self.textfield,
ft.FloatingActionButton(icon=ft.icons.SEARCH, on_click=self.search)
]
),
self.container,
self.results
]
)
async def search(self, sender):
self.ring.visible = True
await self.update_async()
number = self.textfield.value
number_info = await get_number_info(number)
self.ring.visible = False
await self.update_async()
if number_info is None:
self.results.controls = [ft.Text("هیچ زانیاریەک نەدۆزرایەوە")]
await self.update_async()
return
score = number_info["score"]
score = round(score, 2)
score = score * 100
score = round(score, 2)
self.results.controls = [
ft.Text("ئەنجامەکان", text_align=ft.TextAlign.END, size=25),
ft.Text(f"ناو: {number_info['name']}"),
ft.Text(f"ژمارە: {number}"),
ft.Text(f"دڵنیای: %{score}"),
]
await self.update_async()
async def main(page: ft.Page):
page.rtl = True
page.title = "رەقەم دۆزەرەوە"
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
app = KurdishCaller()
page.fonts = {
"NRT-Bold": "fonts/NRT-Bd.ttf",
"NRTReg": "fonts/NRT-Reg.ttf"
}
page.theme = ft.Theme(font_family="NRT-Bold")
page.theme_mode = ft.ThemeMode.LIGHT
await page.update_async()
await page.add_async(app)
ft.app(target=main, assets_dir="assets")