Update app.py
Browse files
app.py
CHANGED
|
@@ -4,28 +4,25 @@ import uvicorn
|
|
| 4 |
from fastapi import FastAPI
|
| 5 |
from huggingface_hub import hf_hub_download
|
| 6 |
|
| 7 |
-
app = FastAPI(
|
| 8 |
-
|
| 9 |
-
# Dataset details
|
| 10 |
-
DATASET_ID = "Watchhrr/Telegram"
|
| 11 |
|
| 12 |
@app.get("/")
|
| 13 |
-
def
|
| 14 |
-
return {"
|
| 15 |
|
| 16 |
@app.get("/search/{user_id}")
|
| 17 |
def search(user_id: str):
|
| 18 |
token = os.getenv("HF_TOKEN")
|
| 19 |
results = []
|
| 20 |
|
| 21 |
-
# Dono
|
| 22 |
dbs = ["Midnight_Master_v2.db", "Telegram_part_1_DB.db"]
|
| 23 |
|
| 24 |
for db_name in dbs:
|
| 25 |
try:
|
| 26 |
-
#
|
| 27 |
path = hf_hub_download(
|
| 28 |
-
repo_id=
|
| 29 |
filename=db_name,
|
| 30 |
repo_type="dataset",
|
| 31 |
token=token
|
|
@@ -34,8 +31,8 @@ def search(user_id: str):
|
|
| 34 |
conn = sqlite3.connect(path)
|
| 35 |
cursor = conn.cursor()
|
| 36 |
|
|
|
|
| 37 |
if "Midnight" in db_name:
|
| 38 |
-
# 27Cr DB search
|
| 39 |
cursor.execute("SELECT user_id FROM telegram_users WHERE user_id LIKE ?", (f"{user_id}%",))
|
| 40 |
for r in cursor.fetchall():
|
| 41 |
parts = r[0].split(';')
|
|
@@ -46,15 +43,10 @@ def search(user_id: str):
|
|
| 46 |
"name": parts[2] if len(parts)>2 else "N/A"
|
| 47 |
})
|
| 48 |
else:
|
| 49 |
-
# 5Cr DB search
|
| 50 |
cursor.execute("SELECT * FROM users WHERE user_id = ?", (user_id,))
|
| 51 |
for r in cursor.fetchall():
|
| 52 |
-
results.append({
|
| 53 |
-
|
| 54 |
-
"phone": r[1],
|
| 55 |
-
"username": r[2],
|
| 56 |
-
"name": f"{r[3]} {r[4] or ''}".strip()
|
| 57 |
-
})
|
| 58 |
conn.close()
|
| 59 |
except Exception as e:
|
| 60 |
print(f"Error: {e}")
|
|
@@ -62,6 +54,5 @@ def search(user_id: str):
|
|
| 62 |
return {"status": "success", "user_id": user_id, "data": results}
|
| 63 |
|
| 64 |
if __name__ == "__main__":
|
| 65 |
-
# Hugging Face default port 7860 use karna zaroori hai
|
| 66 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
| 67 |
|
|
|
|
| 4 |
from fastapi import FastAPI
|
| 5 |
from huggingface_hub import hf_hub_download
|
| 6 |
|
| 7 |
+
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
@app.get("/")
|
| 10 |
+
def read_root():
|
| 11 |
+
return {"status": "Midnight API Online"}
|
| 12 |
|
| 13 |
@app.get("/search/{user_id}")
|
| 14 |
def search(user_id: str):
|
| 15 |
token = os.getenv("HF_TOKEN")
|
| 16 |
results = []
|
| 17 |
|
| 18 |
+
# Dono DBs ki list
|
| 19 |
dbs = ["Midnight_Master_v2.db", "Telegram_part_1_DB.db"]
|
| 20 |
|
| 21 |
for db_name in dbs:
|
| 22 |
try:
|
| 23 |
+
# Dataset se file link uthana
|
| 24 |
path = hf_hub_download(
|
| 25 |
+
repo_id="Watchhrr/Telegram",
|
| 26 |
filename=db_name,
|
| 27 |
repo_type="dataset",
|
| 28 |
token=token
|
|
|
|
| 31 |
conn = sqlite3.connect(path)
|
| 32 |
cursor = conn.cursor()
|
| 33 |
|
| 34 |
+
# DB Type ke hisab se query
|
| 35 |
if "Midnight" in db_name:
|
|
|
|
| 36 |
cursor.execute("SELECT user_id FROM telegram_users WHERE user_id LIKE ?", (f"{user_id}%",))
|
| 37 |
for r in cursor.fetchall():
|
| 38 |
parts = r[0].split(';')
|
|
|
|
| 43 |
"name": parts[2] if len(parts)>2 else "N/A"
|
| 44 |
})
|
| 45 |
else:
|
|
|
|
| 46 |
cursor.execute("SELECT * FROM users WHERE user_id = ?", (user_id,))
|
| 47 |
for r in cursor.fetchall():
|
| 48 |
+
results.append({"db": "Part_1", "phone": r[1], "username": r[2], "name": f"{r[3]} {r[4] or ''}".strip()})
|
| 49 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
conn.close()
|
| 51 |
except Exception as e:
|
| 52 |
print(f"Error: {e}")
|
|
|
|
| 54 |
return {"status": "success", "user_id": user_id, "data": results}
|
| 55 |
|
| 56 |
if __name__ == "__main__":
|
|
|
|
| 57 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
| 58 |
|