Update app.py
Browse files
app.py
CHANGED
|
@@ -51,7 +51,7 @@ ASUR_KEY = os.environ.get("ASUR_KEY", "@ASUR_ABOUT").strip()
|
|
| 51 |
BACKUP_CHANNEL_ID = os.environ.get("BACKUP_CHANNEL_ID", "").strip()
|
| 52 |
BACKUP_ENABLED = bool(BACKUP_CHANNEL_ID)
|
| 53 |
TELEGRAM_API = f"https://api.telegram.org/bot{BOT_TOKEN}"
|
| 54 |
-
VERSION = "4.1.
|
| 55 |
BOT_NAME = "Phone Lookup Bot"
|
| 56 |
|
| 57 |
HITECK_URLS = [f"https://huggingface.co/datasets/HiTeckGroup/HiTeckgroop/resolve/main/idx_phone.{i}.parquet" for i in range(7)]
|
|
@@ -104,13 +104,10 @@ def get_con():
|
|
| 104 |
try:
|
| 105 |
c = duckdb.connect(":memory:")
|
| 106 |
c.execute("INSTALL httpfs; LOAD httpfs;")
|
| 107 |
-
if HF_TOKEN:
|
| 108 |
-
c.execute(f"CREATE SECRET hf (TYPE HUGGINGFACE, TOKEN '{HF_TOKEN}');")
|
| 109 |
c.execute("SET enable_object_cache=true; SET preserve_insertion_order=false; SET threads=6; SET memory_limit='12GB';")
|
| 110 |
_con = c; con_ready.set(); return _con
|
| 111 |
-
except Exception as e:
|
| 112 |
-
log.error(f"DuckDB Init failed: {e!r}")
|
| 113 |
-
return None
|
| 114 |
|
| 115 |
def run_search_safe(phone, limit=FETCH_LIMIT, timeout_secs=QUERY_TIMEOUT):
|
| 116 |
con = get_con()
|
|
@@ -144,9 +141,7 @@ def run_search_safe(phone, limit=FETCH_LIMIT, timeout_secs=QUERY_TIMEOUT):
|
|
| 144 |
except: pass
|
| 145 |
results.append(rec)
|
| 146 |
return results
|
| 147 |
-
except Exception as e:
|
| 148 |
-
log.error(f"DB Search failed: {e!r}")
|
| 149 |
-
return []
|
| 150 |
finally: stop.set()
|
| 151 |
|
| 152 |
def warm_phone_cache():
|
|
@@ -174,10 +169,17 @@ def _record_has_content(rec): return any(str(rec.get(k, "")).strip().lower() not
|
|
| 174 |
def _drop_empty_records(records): return [r for r in records if _record_has_content(r)]
|
| 175 |
|
| 176 |
async def _q_cr850_raw(client, number):
|
| 177 |
-
try:
|
|
|
|
|
|
|
|
|
|
| 178 |
except Exception as e: log.warning(f"850CR Fail: {e}"); return None
|
|
|
|
| 179 |
async def _q_inddata_raw(client, number):
|
| 180 |
-
try:
|
|
|
|
|
|
|
|
|
|
| 181 |
except Exception as e: log.warning(f"IndData Fail: {e}"); return None
|
| 182 |
|
| 183 |
async def search_fast_apis_filtered(phone):
|
|
@@ -210,7 +212,9 @@ async def search_fast_apis_filtered(phone):
|
|
| 210 |
async def fetch_asurpapa_all(mobile, aadhaar):
|
| 211 |
results = {}
|
| 212 |
async with httpx.AsyncClient(timeout=30) as cli:
|
| 213 |
-
try:
|
|
|
|
|
|
|
| 214 |
except Exception as e: results["num_to_info"] = {"error": str(e)}
|
| 215 |
|
| 216 |
if not aadhaar:
|
|
@@ -218,14 +222,20 @@ async def fetch_asurpapa_all(mobile, aadhaar):
|
|
| 218 |
return results
|
| 219 |
|
| 220 |
async def _call(name):
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
|
| 230 |
gathered = await asyncio.gather(_call("aadhaar_to_info"), _call("aadhaar_family"), _call("aadhaar_ration"))
|
| 231 |
for name, res in gathered: results[name] = res
|
|
@@ -369,7 +379,7 @@ async def _is_channel_member(uid):
|
|
| 369 |
is_m = False
|
| 370 |
res = await tg("getChatMember", {"chat_id": FORCE_JOIN_CHANNEL, "user_id": uid})
|
| 371 |
if res.get("ok"): is_m = res.get("result", {}).get("status") in ("member", "administrator", "creator")
|
| 372 |
-
else: log.warning(f"Force Join Check Failed
|
| 373 |
with _member_lock: _member_cache[uid] = (is_m, time.time())
|
| 374 |
return is_m
|
| 375 |
|
|
|
|
| 51 |
BACKUP_CHANNEL_ID = os.environ.get("BACKUP_CHANNEL_ID", "").strip()
|
| 52 |
BACKUP_ENABLED = bool(BACKUP_CHANNEL_ID)
|
| 53 |
TELEGRAM_API = f"https://api.telegram.org/bot{BOT_TOKEN}"
|
| 54 |
+
VERSION = "4.1.1"
|
| 55 |
BOT_NAME = "Phone Lookup Bot"
|
| 56 |
|
| 57 |
HITECK_URLS = [f"https://huggingface.co/datasets/HiTeckGroup/HiTeckgroop/resolve/main/idx_phone.{i}.parquet" for i in range(7)]
|
|
|
|
| 104 |
try:
|
| 105 |
c = duckdb.connect(":memory:")
|
| 106 |
c.execute("INSTALL httpfs; LOAD httpfs;")
|
| 107 |
+
if HF_TOKEN: c.execute(f"CREATE SECRET hf (TYPE HUGGINGFACE, TOKEN '{HF_TOKEN}');")
|
|
|
|
| 108 |
c.execute("SET enable_object_cache=true; SET preserve_insertion_order=false; SET threads=6; SET memory_limit='12GB';")
|
| 109 |
_con = c; con_ready.set(); return _con
|
| 110 |
+
except Exception as e: log.error(f"DuckDB Init failed: {e!r}"); return None
|
|
|
|
|
|
|
| 111 |
|
| 112 |
def run_search_safe(phone, limit=FETCH_LIMIT, timeout_secs=QUERY_TIMEOUT):
|
| 113 |
con = get_con()
|
|
|
|
| 141 |
except: pass
|
| 142 |
results.append(rec)
|
| 143 |
return results
|
| 144 |
+
except Exception as e: log.error(f"DB Search failed: {e!r}"); return []
|
|
|
|
|
|
|
| 145 |
finally: stop.set()
|
| 146 |
|
| 147 |
def warm_phone_cache():
|
|
|
|
| 169 |
def _drop_empty_records(records): return [r for r in records if _record_has_content(r)]
|
| 170 |
|
| 171 |
async def _q_cr850_raw(client, number):
|
| 172 |
+
try:
|
| 173 |
+
r = await client.get(f"{API_850CR}/{number}", timeout=40)
|
| 174 |
+
if r.status_code == 200: return r.json()
|
| 175 |
+
return None
|
| 176 |
except Exception as e: log.warning(f"850CR Fail: {e}"); return None
|
| 177 |
+
|
| 178 |
async def _q_inddata_raw(client, number):
|
| 179 |
+
try:
|
| 180 |
+
r = await client.get(API_INDDATA, params={"mobile": number}, timeout=30)
|
| 181 |
+
if r.status_code == 200: return r.json()
|
| 182 |
+
return None
|
| 183 |
except Exception as e: log.warning(f"IndData Fail: {e}"); return None
|
| 184 |
|
| 185 |
async def search_fast_apis_filtered(phone):
|
|
|
|
| 212 |
async def fetch_asurpapa_all(mobile, aadhaar):
|
| 213 |
results = {}
|
| 214 |
async with httpx.AsyncClient(timeout=30) as cli:
|
| 215 |
+
try:
|
| 216 |
+
r = await cli.get(ASUR_API["num_to_info"], params={"key": ASUR_KEY, "number": mobile})
|
| 217 |
+
results["num_to_info"] = r.json() if r.status_code == 200 else {"error": f"HTTP {r.status_code}"}
|
| 218 |
except Exception as e: results["num_to_info"] = {"error": str(e)}
|
| 219 |
|
| 220 |
if not aadhaar:
|
|
|
|
| 222 |
return results
|
| 223 |
|
| 224 |
async def _call(name):
|
| 225 |
+
for attempt in range(2): # Retry once if 503
|
| 226 |
+
try:
|
| 227 |
+
r = await cli.get(ASUR_API[name], params={"key": ASUR_KEY, ASUR_PARAM_NAMES[name]: aadhaar})
|
| 228 |
+
if r.status_code == 200:
|
| 229 |
+
j = r.json()
|
| 230 |
+
log.info(f"ASUR {name}: {j}")
|
| 231 |
+
return name, j
|
| 232 |
+
elif r.status_code == 503:
|
| 233 |
+
await asyncio.sleep(1)
|
| 234 |
+
continue
|
| 235 |
+
else:
|
| 236 |
+
return name, {"error": f"HTTP {r.status_code}"}
|
| 237 |
+
except Exception as e:
|
| 238 |
+
if attempt == 1: return name, {"error": str(e)}
|
| 239 |
|
| 240 |
gathered = await asyncio.gather(_call("aadhaar_to_info"), _call("aadhaar_family"), _call("aadhaar_ration"))
|
| 241 |
for name, res in gathered: results[name] = res
|
|
|
|
| 379 |
is_m = False
|
| 380 |
res = await tg("getChatMember", {"chat_id": FORCE_JOIN_CHANNEL, "user_id": uid})
|
| 381 |
if res.get("ok"): is_m = res.get("result", {}).get("status") in ("member", "administrator", "creator")
|
| 382 |
+
else: log.warning(f"Force Join Check Failed: {res}")
|
| 383 |
with _member_lock: _member_cache[uid] = (is_m, time.time())
|
| 384 |
return is_m
|
| 385 |
|