Upload app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,8 @@ from fastapi.responses import HTMLResponse, JSONResponse
|
|
| 3 |
import sqlite3, os, re, threading
|
| 4 |
from pathlib import Path
|
| 5 |
from huggingface_hub import hf_hub_download, HfApi
|
|
|
|
|
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
|
@@ -33,7 +35,7 @@ PROVINCES = [
|
|
| 33 |
]
|
| 34 |
PROVINCE_MAP = {p["key"]: p for p in PROVINCES}
|
| 35 |
|
| 36 |
-
# โโโ TEXT โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 37 |
|
| 38 |
DIACRITICS = re.compile(r'[\u064B-\u065F\u0610-\u061A\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]')
|
| 39 |
ARABIC_ONLY = re.compile('[^\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF\s]')
|
|
@@ -80,7 +82,7 @@ def row_to_dict(row) -> dict:
|
|
| 80 |
"full_name": f"{f} {fa} {g}".strip(),
|
| 81 |
}
|
| 82 |
|
| 83 |
-
# โโโ
|
| 84 |
|
| 85 |
def download_db(filename):
|
| 86 |
local = DB_DIR / filename
|
|
@@ -125,7 +127,180 @@ def fam_candidates(fam):
|
|
| 125 |
except: pass
|
| 126 |
return s
|
| 127 |
|
| 128 |
-
# โโโ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
SMALL_FILES = ["balad","muthana","duhok","karbalaa","salahaldeen","mesan","qadisiya","wasit","kirkuk"]
|
| 131 |
|
|
@@ -142,83 +317,10 @@ def preload():
|
|
| 142 |
@app.on_event("startup")
|
| 143 |
async def startup():
|
| 144 |
threading.Thread(target=preload, daemon=True).start()
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
def search(p: str = Query(...), name: str = Query(None), fam: str = Query(None)):
|
| 150 |
-
try:
|
| 151 |
-
db_path = get_db_path(p)
|
| 152 |
-
if not db_path: return JSONResponse({"error": "ู
ุญุงูุธุฉ ุบูุฑ ู
ูุฌูุฏุฉ"}, 404)
|
| 153 |
-
conn = open_db(db_path)
|
| 154 |
-
table = get_table(conn)
|
| 155 |
-
if not table: return JSONResponse({"error": "ูุงุนุฏุฉ ุงูุจูุงูุงุช ูุงุฑุบุฉ"}, 500)
|
| 156 |
-
|
| 157 |
-
results, seen = [], set()
|
| 158 |
-
fuzzy = False
|
| 159 |
-
|
| 160 |
-
if fam:
|
| 161 |
-
for c in fam_candidates(fam):
|
| 162 |
-
for row in conn.execute(f"SELECT fam_no,p_first,p_father,p_grand,p_birth FROM [{table}] WHERE fam_no=? LIMIT 200", (c,)).fetchall():
|
| 163 |
-
d = row_to_dict(row)
|
| 164 |
-
k = (d["fam_no"], d["p_first"], d["p_father"], d["p_grand"])
|
| 165 |
-
if k not in seen: seen.add(k); results.append(d)
|
| 166 |
-
|
| 167 |
-
elif name:
|
| 168 |
-
words = name.strip().split()
|
| 169 |
-
if len(words) < 3:
|
| 170 |
-
conn.close()
|
| 171 |
-
return JSONResponse({"error": "ูุฑุฌู ุฅุฏุฎุงู ุงูุงุณู
ุงูุซูุงุซู ูุงู
ูุงู"})
|
| 172 |
-
|
| 173 |
-
norm_words = [normalize(w) for w in words]
|
| 174 |
-
|
| 175 |
-
# โโ Exact search first โโ
|
| 176 |
-
for first, father, grand in name_combos(norm_words):
|
| 177 |
-
for row in conn.execute(
|
| 178 |
-
f"SELECT fam_no,p_first,p_father,p_grand,p_birth FROM [{table}] WHERE NORM(p_first)=? AND NORM(p_father)=? AND NORM(p_grand)=? LIMIT 300",
|
| 179 |
-
(first, father, grand)).fetchall():
|
| 180 |
-
d = row_to_dict(row)
|
| 181 |
-
k = (d["fam_no"], d["p_first"], d["p_father"], d["p_grand"])
|
| 182 |
-
if k not in seen: seen.add(k); results.append(d)
|
| 183 |
-
|
| 184 |
-
# โโ Fuzzy fallback: search by first+father only โโ
|
| 185 |
-
if not results and len(norm_words) >= 2:
|
| 186 |
-
fuzzy = True
|
| 187 |
-
for i in range(1, len(norm_words)):
|
| 188 |
-
first = "".join(norm_words[:i])
|
| 189 |
-
father = "".join(norm_words[i:])
|
| 190 |
-
for row in conn.execute(
|
| 191 |
-
f"SELECT fam_no,p_first,p_father,p_grand,p_birth FROM [{table}] WHERE NORM(p_first)=? AND NORM(p_father)=? LIMIT 100",
|
| 192 |
-
(first, father)).fetchall():
|
| 193 |
-
d = row_to_dict(row)
|
| 194 |
-
k = (d["fam_no"], d["p_first"], d["p_father"], d["p_grand"])
|
| 195 |
-
if k not in seen: seen.add(k); results.append(d)
|
| 196 |
-
|
| 197 |
-
conn.close()
|
| 198 |
-
return JSONResponse({"results": results, "count": len(results),
|
| 199 |
-
"mode": "fam" if fam else "name", "fuzzy": fuzzy})
|
| 200 |
-
except Exception as e:
|
| 201 |
-
return JSONResponse({"error": str(e)}, 500)
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
@app.get("/api/family")
|
| 205 |
-
def family(p: str = Query(...), fam: str = Query(...)):
|
| 206 |
-
try:
|
| 207 |
-
db_path = get_db_path(p)
|
| 208 |
-
if not db_path: return JSONResponse({"error": "ู
ุญุงูุธุฉ ุบูุฑ ู
ูุฌูุฏุฉ"}, 404)
|
| 209 |
-
conn = open_db(db_path)
|
| 210 |
-
table = get_table(conn)
|
| 211 |
-
members, seen = [], set()
|
| 212 |
-
for c in fam_candidates(fam):
|
| 213 |
-
for row in conn.execute(f"SELECT fam_no,p_first,p_father,p_grand,p_birth FROM [{table}] WHERE fam_no=? LIMIT 100", (c,)).fetchall():
|
| 214 |
-
d = row_to_dict(row)
|
| 215 |
-
k = (d["p_first"], d["p_father"], d["p_grand"])
|
| 216 |
-
if k not in seen: seen.add(k); members.append(d)
|
| 217 |
-
conn.close()
|
| 218 |
-
return JSONResponse({"members": members, "count": len(members)})
|
| 219 |
-
except Exception as e:
|
| 220 |
-
return JSONResponse({"error": str(e)}, 500)
|
| 221 |
-
|
| 222 |
|
| 223 |
# โโโ PAGES โโโโโโโโโโโโโโโโ๏ฟฝ๏ฟฝโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 224 |
|
|
@@ -951,7 +1053,7 @@ function renderName(results, fuzzy){{
|
|
| 951 |
<div class="rinfo">
|
| 952 |
<div class="rname">${{r.full_name}}</div>
|
| 953 |
<div class="rmeta">
|
| 954 |
-
<span class="mitem"><i class="ti ti-calendar"></i> ${{r.p_birth||'ุบูุฑ ู
ุญ
|
| 955 |
<span class="ftag"><i class="ti ti-id"></i> ุนุงุฆูุฉ ${{r.fam_no}}</span>
|
| 956 |
</div>
|
| 957 |
</div>
|
|
@@ -1271,15 +1373,13 @@ ADMIN_HTML = """<!DOCTYPE html>
|
|
| 1271 |
.srow input:focus{border-color:var(--ac);box-shadow:0 0 0 3px var(--acg);background:var(--sf)}
|
| 1272 |
.srow button{padding:12px 24px;background:var(--ac);color:#fff;border:none;border-radius:var(--r);font-family:inherit;font-size:14px;font-weight:700;cursor:pointer}
|
| 1273 |
|
| 1274 |
-
.ritem{display:flex;align-items:center;justify-content:space-between;padding:14px 18px;border:1.5px solid var(--bd);border-radius:var(--r);margin-bottom:
|
| 1275 |
-
.
|
| 1276 |
-
.
|
| 1277 |
-
.
|
| 1278 |
-
|
| 1279 |
-
.
|
| 1280 |
-
.ibtn{
|
| 1281 |
-
.ibtn:hover{background:var(--sf3);color:var(--tx);border-color:var(--bd3)}
|
| 1282 |
-
.ibtn.rd:hover{background:var(--rdd);color:var(--rd);border-color:var(--rd)}
|
| 1283 |
.ibtn.ac:hover{background:var(--acd);color:var(--ac);border-color:var(--ac)}
|
| 1284 |
|
| 1285 |
/* โโ SAVING BAR MODIFIED โโ */
|
|
@@ -1617,6 +1717,8 @@ ADMIN_HTML = """<!DOCTYPE html>
|
|
| 1617 |
</body></html>"""
|
| 1618 |
|
| 1619 |
|
|
|
|
|
|
|
| 1620 |
@app.get("/", response_class=HTMLResponse)
|
| 1621 |
def index():
|
| 1622 |
return HTMLResponse(INDEX_HTML)
|
|
|
|
| 3 |
import sqlite3, os, re, threading
|
| 4 |
from pathlib import Path
|
| 5 |
from huggingface_hub import hf_hub_download, HfApi
|
| 6 |
+
import telebot
|
| 7 |
+
from telebot import types
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
|
|
|
| 35 |
]
|
| 36 |
PROVINCE_MAP = {p["key"]: p for p in PROVINCES}
|
| 37 |
|
| 38 |
+
# โโโ TEXT PROCESSING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 39 |
|
| 40 |
DIACRITICS = re.compile(r'[\u064B-\u065F\u0610-\u061A\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]')
|
| 41 |
ARABIC_ONLY = re.compile('[^\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF\s]')
|
|
|
|
| 82 |
"full_name": f"{f} {fa} {g}".strip(),
|
| 83 |
}
|
| 84 |
|
| 85 |
+
# โโโ DATABASE OPERATIONS โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 86 |
|
| 87 |
def download_db(filename):
|
| 88 |
local = DB_DIR / filename
|
|
|
|
| 127 |
except: pass
|
| 128 |
return s
|
| 129 |
|
| 130 |
+
# โโโ TELEGRAM BOT LOGIC โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 131 |
+
|
| 132 |
+
BOT_TOKEN = os.environ.get("TELEGRAM_BOT_TOKEN")
|
| 133 |
+
bot = telebot.TeleBot(BOT_TOKEN) if BOT_TOKEN else None
|
| 134 |
+
user_states = {} # ุญูุธ ุญุงูุฉ ุงุฎุชูุงุฑ ุงูู
ุญุงูุธุฉ ููู
ุณุชุฎุฏู
ูู {chat_id: province_key}
|
| 135 |
+
|
| 136 |
+
def build_provinces_keyboard():
|
| 137 |
+
keyboard = types.InlineKeyboardMarkup(row_width=3)
|
| 138 |
+
buttons = [types.InlineKeyboardButton(text=p["name"], callback_data=f"prov_{p['key']}") for p in PROVINCES]
|
| 139 |
+
keyboard.add(*buttons)
|
| 140 |
+
return keyboard
|
| 141 |
+
|
| 142 |
+
if bot:
|
| 143 |
+
@bot.message_handler(commands=['start', 'help'])
|
| 144 |
+
def send_welcome(message):
|
| 145 |
+
user_states[message.chat.id] = None
|
| 146 |
+
bot.send_message(
|
| 147 |
+
message.chat.id,
|
| 148 |
+
"ู
ุฑุญุจุงู ุจู ูู ูุธุงู
ุงุณุชุนูุงู
ุงูุณุฌูุงุช.\nุงูุฑุฌุงุก ุงุฎุชูุงุฑ ุงูู
ุญุงูุธุฉ ุงูู
ุทููุจุฉ ู
ู ุงููุงุฆู
ุฉ ุฃุฏูุงู ููุจุฏุก:",
|
| 149 |
+
reply_markup=build_provinces_keyboard()
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
@bot.callback_query_handler(func=lambda call: call.data.startswith("prov_"))
|
| 153 |
+
def handle_province_selection(call):
|
| 154 |
+
prov_key = call.data.replace("prov_", "")
|
| 155 |
+
prov_name = PROVINCE_MAP[prov_key]["name"]
|
| 156 |
+
user_states[call.message.chat.id] = prov_key
|
| 157 |
+
|
| 158 |
+
bot.answer_callback_query(call.id, f"ุชู
ุงุฎุชูุงุฑ {prov_name}")
|
| 159 |
+
bot.edit_message_text(
|
| 160 |
+
chat_id=call.message.chat.id,
|
| 161 |
+
message_id=call.message.message_id,
|
| 162 |
+
text=f"๐ ุงูู
ุญุงูุธุฉ ุงูู
ุญุฏุฏุฉ: *{prov_name}*\n\nุงูุขู ุฃุฑุณู *ุงูุงุณู
ุงูุซูุงุซู* ูุงู
ูุงู (ุงูุงุณู
ูุงุณู
ุงูุฃุจ ูุงูุฌุฏ) ุฃู *ุฑูู
ุงูุนุงุฆูุฉ* ููุจุญุซ ุนูู:",
|
| 163 |
+
parse_mode="Markdown"
|
| 164 |
+
)
|
| 165 |
+
|
| 166 |
+
@bot.message_handler(func=lambda message: True)
|
| 167 |
+
def handle_search_query(message):
|
| 168 |
+
chat_id = message.chat.id
|
| 169 |
+
prov_key = user_states.get(chat_id)
|
| 170 |
+
|
| 171 |
+
if not prov_key:
|
| 172 |
+
bot.send_message(chat_id, "โ ๏ธ ูุฑุฌู ุงุฎุชูุงุฑ ุงูู
ุญุงูุธุฉ ุฃููุงู ุจุงูุถุบุท ุนูู /start")
|
| 173 |
+
return
|
| 174 |
+
|
| 175 |
+
query = message.text.strip()
|
| 176 |
+
prov_name = PROVINCE_MAP[prov_key]["name"]
|
| 177 |
+
|
| 178 |
+
bot.send_message(chat_id, "๐ ุฌุงุฑู ุงูุจุญุซ ูู ุงูุณุฌูุงุช...")
|
| 179 |
+
|
| 180 |
+
try:
|
| 181 |
+
db_path = get_db_path(prov_key)
|
| 182 |
+
if not db_path:
|
| 183 |
+
bot.send_message(chat_id, "โ ุฎุทุฃ: ูุงุนุฏุฉ ุจูุงูุงุช ุงูู
ุญุงูุธุฉ ุบูุฑ ู
ุชููุฑุฉ ุญุงููุงู.")
|
| 184 |
+
return
|
| 185 |
+
|
| 186 |
+
conn = open_db(db_path)
|
| 187 |
+
table = get_table(conn)
|
| 188 |
+
|
| 189 |
+
results, seen = [], set()
|
| 190 |
+
fuzzy = False
|
| 191 |
+
|
| 192 |
+
if query.isdigit():
|
| 193 |
+
# ุจุญุซ ุจุฑูู
ุงูุนุงุฆูุฉ
|
| 194 |
+
for c in fam_candidates(query):
|
| 195 |
+
for row in conn.execute(f"SELECT fam_no,p_first,p_father,p_grand,p_birth FROM [{table}] WHERE fam_no=? LIMIT 50", (c,)).fetchall():
|
| 196 |
+
d = row_to_dict(row)
|
| 197 |
+
k = (d["fam_no"], d["p_first"], d["p_father"], d["p_grand"])
|
| 198 |
+
if k not in seen:
|
| 199 |
+
seen.add(k)
|
| 200 |
+
results.append(d)
|
| 201 |
+
else:
|
| 202 |
+
# ุจุญุซ ุจุงูุงุณู
|
| 203 |
+
words = query.split()
|
| 204 |
+
if len(words) < 3:
|
| 205 |
+
bot.send_message(chat_id, "โ ๏ธ ูุฑุฌู ุฅุฏุฎุงู ุงูุงุณู
ุงูุซูุงุซู ูุงู
ูุงู ูุถู
ุงู ุฏูุฉ ุงูุจุญุซ.")
|
| 206 |
+
conn.close()
|
| 207 |
+
return
|
| 208 |
+
|
| 209 |
+
norm_words = [normalize(w) for w in words]
|
| 210 |
+
for first, father, grand in name_combos(norm_words):
|
| 211 |
+
for row in conn.execute(
|
| 212 |
+
f"SELECT fam_no,p_first,p_father,p_grand,p_birth FROM [{table}] WHERE NORM(p_first)=? AND NORM(p_father)=? AND NORM(p_grand)=? LIMIT 50",
|
| 213 |
+
(first, father, grand)).fetchall():
|
| 214 |
+
d = row_to_dict(row)
|
| 215 |
+
k = (d["fam_no"], d["p_first"], d["p_father"], d["p_grand"])
|
| 216 |
+
if k not in seen:
|
| 217 |
+
seen.add(k)
|
| 218 |
+
results.append(d)
|
| 219 |
+
|
| 220 |
+
# ุงูุจุญุซ ุงูุชูุฑูุจู ูู ุญุงู ุนุฏู
ูุฌูุฏ ูุชุงุฆุฌ ู
ุทุงุจูุฉ ุชู
ุงู
ุงู
|
| 221 |
+
if not results and len(norm_words) >= 2:
|
| 222 |
+
fuzzy = True
|
| 223 |
+
for i in range(1, len(norm_words)):
|
| 224 |
+
first = "".join(norm_words[:i])
|
| 225 |
+
father = "".join(norm_words[i:])
|
| 226 |
+
for row in conn.execute(
|
| 227 |
+
f"SELECT fam_no,p_first,p_father,p_grand,p_birth FROM [{table}] WHERE NORM(p_first)=? AND NORM(p_father)=? LIMIT 20",
|
| 228 |
+
(first, father)).fetchall():
|
| 229 |
+
d = row_to_dict(row)
|
| 230 |
+
k = (d["fam_no"], d["p_first"], d["p_father"], d["p_grand"])
|
| 231 |
+
if k not in seen:
|
| 232 |
+
seen.add(k)
|
| 233 |
+
results.append(d)
|
| 234 |
+
|
| 235 |
+
conn.close()
|
| 236 |
+
|
| 237 |
+
if not results:
|
| 238 |
+
bot.send_message(chat_id, "โ ูู
ูุชู
ุงูุนุซูุฑ ุนูู ูุชุงุฆุฌ ุชุทุงุจู ูุฐุง ุงูุจุญุซ ูู ูุงุนุฏุฉ ุงูุจูุงูุงุช.")
|
| 239 |
+
return
|
| 240 |
+
|
| 241 |
+
# ุฅุฑุณุงู ุงููุชุงุฆุฌ ููู
ุณุชุฎุฏู
|
| 242 |
+
response_msg = f"๐ ูุชุงุฆุฌ ุงูุจุญุซ ูู *{prov_name}* ({len(results)} ููุฏ):\n"
|
| 243 |
+
if fuzzy:
|
| 244 |
+
response_msg += "โ ๏ธ _ู
ูุงุญุธุฉ: ูุฐู ูุชุงุฆุฌ ุชูุฑูุจูุฉ ูุนุฏู
ุชุทุงุจู ุงูุงุณู
ุจุงููุงู
ู_\n"
|
| 245 |
+
response_msg += "โ" * 15 + "\n\n"
|
| 246 |
+
|
| 247 |
+
for i, r in enumerate(results[:15]): # ุฅุธูุงุฑ ุฃูู 15 ูุชูุฌุฉ ูุชูุงุฏู ุทูู ุงูุฑุณุงูุฉ
|
| 248 |
+
response_msg += f"{i+1} ๐ค *{r['full_name']}*\n"
|
| 249 |
+
response_msg += f"๐
ุงูู
ูุงููุฏ: `{r['p_birth'] or 'ุบูุฑ ู
ุญุฏุฏ'}`\n"
|
| 250 |
+
response_msg += f"๐ข ุฑูู
ุงูุนุงุฆูุฉ: `{r['fam_no']}`\n"
|
| 251 |
+
response_msg += f"๐ /fam\_{prov_key}\_{r['fam_no']} (ูุนุฑุถ ุงูุนุงุฆูุฉ)\n\n"
|
| 252 |
+
|
| 253 |
+
if len(results) > 15:
|
| 254 |
+
response_msg += f"โน๏ธ ุชู
ุนุฑุถ ุฃูู 15 ูุชูุฌุฉ ู
ู ุฃุตู {len(results)}."
|
| 255 |
+
|
| 256 |
+
bot.send_message(chat_id, response_msg, parse_mode="Markdown")
|
| 257 |
+
|
| 258 |
+
except Exception as e:
|
| 259 |
+
bot.send_message(chat_id, f"โ ุญุฏุซ ุฎุทุฃ ุฏุงุฎูู ุฃุซูุงุก ุงูุจุญุซ: {str(e)}")
|
| 260 |
+
|
| 261 |
+
# ุงูุงุณุชุนูุงู
ุงูุณุฑูุน ูุฃูุฑุงุฏ ุงูุนุงุฆูุฉ ู
ู ุงูุฑูุงุจุท ุงูุฐููุฉ ุงูู
ุฑุณูุฉ ูู ูุชุงุฆุฌ ุงูุจุญุซ
|
| 262 |
+
@bot.message_handler(regexp=r"^/fam_[a-zA-Z0-9_\-]+$")
|
| 263 |
+
def handle_family_command(message):
|
| 264 |
+
chat_id = message.chat.id
|
| 265 |
+
try:
|
| 266 |
+
parts = message.text.split("_")
|
| 267 |
+
if len(parts) < 3:
|
| 268 |
+
return
|
| 269 |
+
prov_key = parts[1]
|
| 270 |
+
fam_no = parts[2]
|
| 271 |
+
|
| 272 |
+
db_path = get_db_path(prov_key)
|
| 273 |
+
conn = open_db(db_path)
|
| 274 |
+
table = get_table(conn)
|
| 275 |
+
|
| 276 |
+
members, seen = [], set()
|
| 277 |
+
for c in fam_candidates(fam_no):
|
| 278 |
+
for row in conn.execute(f"SELECT fam_no,p_first,p_father,p_grand,p_birth FROM [{table}] WHERE fam_no=? LIMIT 50", (c,)).fetchall():
|
| 279 |
+
d = row_to_dict(row)
|
| 280 |
+
k = (d["p_first"], d["p_father"], d["p_grand"])
|
| 281 |
+
if k not in seen:
|
| 282 |
+
seen.add(k)
|
| 283 |
+
members.append(d)
|
| 284 |
+
conn.close()
|
| 285 |
+
|
| 286 |
+
if not members:
|
| 287 |
+
bot.send_message(chat_id, "โ ูู
ูุชู
ุงูุนุซูุฑ ุนูู ุฃูุฑุงุฏ ููุฐู ุงูุนุงุฆูุฉ.")
|
| 288 |
+
return
|
| 289 |
+
|
| 290 |
+
response_msg = f"๐จโ๐ฉโ๐งโ๐ฆ ุฃูุฑุงุฏ ุงูุนุงุฆูุฉ ููุฑูู
`{fam_no}`:\n"
|
| 291 |
+
response_msg += "โ" * 15 + "\n\n"
|
| 292 |
+
for i, m in enumerate(members):
|
| 293 |
+
response_msg += f"{i+1} ๐ค {m['full_name']} | `๐
{m['p_birth'] or 'โ'}`\n"
|
| 294 |
+
|
| 295 |
+
bot.send_message(chat_id, response_msg, parse_mode="Markdown")
|
| 296 |
+
except Exception as e:
|
| 297 |
+
bot.send_message(chat_id, f"โ ุญุฏุซ ุฎุทุฃ ุฃุซูุงุก ุฌูุจ ุงููููุฏ ุงูุนุงุฆููุฉ: {str(e)}")
|
| 298 |
+
|
| 299 |
+
def run_bot_polling():
|
| 300 |
+
print("๐ค Telegram Bot thread started and waiting for updates...")
|
| 301 |
+
bot.infinity_polling()
|
| 302 |
+
|
| 303 |
+
# โโโ PRELOAD BACKGROUND THREAD โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 304 |
|
| 305 |
SMALL_FILES = ["balad","muthana","duhok","karbalaa","salahaldeen","mesan","qadisiya","wasit","kirkuk"]
|
| 306 |
|
|
|
|
| 317 |
@app.on_event("startup")
|
| 318 |
async def startup():
|
| 319 |
threading.Thread(target=preload, daemon=True).start()
|
| 320 |
+
if bot:
|
| 321 |
+
threading.Thread(target=run_bot_polling, daemon=True).start()
|
| 322 |
+
else:
|
| 323 |
+
print("โ ๏ธ Warning: TELEGRAM_BOT_TOKEN environment variable not found. Bot disabled.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
|
| 325 |
# โโโ PAGES โโโโโโโโโโโโโโโโ๏ฟฝ๏ฟฝโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 326 |
|
|
|
|
| 1053 |
<div class="rinfo">
|
| 1054 |
<div class="rname">${{r.full_name}}</div>
|
| 1055 |
<div class="rmeta">
|
| 1056 |
+
<span class="mitem"><i class="ti ti-calendar"></i> ${{r.p_birth||'ุบูุฑ ู
ุญุฏุฏ'}}</span>
|
| 1057 |
<span class="ftag"><i class="ti ti-id"></i> ุนุงุฆูุฉ ${{r.fam_no}}</span>
|
| 1058 |
</div>
|
| 1059 |
</div>
|
|
|
|
| 1373 |
.srow input:focus{border-color:var(--ac);box-shadow:0 0 0 3px var(--acg);background:var(--sf)}
|
| 1374 |
.srow button{padding:12px 24px;background:var(--ac);color:#fff;border:none;border-radius:var(--r);font-family:inherit;font-size:14px;font-weight:700;cursor:pointer}
|
| 1375 |
|
| 1376 |
+
.ritem{display:flex;align-items:center;justify-content:space-between;padding:14px 18px;border:1.5px solid var(--bd);border-radius:var(--r);margin-bottom:8px;background:var(--sf)}
|
| 1377 |
+
.rname{font-size:14px;font-weight:500;color:var(--tx)}
|
| 1378 |
+
.rmeta{font-size:12px;color:var(--tx3);margin-top:2px}
|
| 1379 |
+
.ract{display:flex;gap:6px}
|
| 1380 |
+
.ibtn{width:34px;height:34px;border:1px solid var(--bd2);border-radius:var(--r);background:transparent;cursor:pointer;display:flex;align-items:center;justify-content:center;color:var(--tx2);font-size:16px;transition:all .15s}
|
| 1381 |
+
.ibtn:hover{background:var(--sf2);color:var(--tx)}
|
| 1382 |
+
.ibtn.rd:hover{background:var(--rdd);color:var(--rd);border-color:var(--rdb)}
|
|
|
|
|
|
|
| 1383 |
.ibtn.ac:hover{background:var(--acd);color:var(--ac);border-color:var(--ac)}
|
| 1384 |
|
| 1385 |
/* โโ SAVING BAR MODIFIED โโ */
|
|
|
|
| 1717 |
</body></html>"""
|
| 1718 |
|
| 1719 |
|
| 1720 |
+
# โโโ API ROUTES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1721 |
+
|
| 1722 |
@app.get("/", response_class=HTMLResponse)
|
| 1723 |
def index():
|
| 1724 |
return HTMLResponse(INDEX_HTML)
|