Watchhrr commited on
Commit
aa34e2c
·
verified ·
1 Parent(s): 7eeac5b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ import sqlite3
3
+ import os
4
+
5
+ app = FastAPI()
6
+
7
+ # Database ka path (Hugging Face Dataset se connect karne ke liye)
8
+ # Agar aapne database isi Space mein upload kiya hai toh:
9
+ DB_PATH = "Telegram_Master_DB.db"
10
+
11
+ @app.get("/search")
12
+ def search(num: str = None, id: str = None):
13
+ if not os.path.exists(DB_PATH):
14
+ return {"error": "Database file nahi mili bhai!"}
15
+
16
+ conn = sqlite3.connect(DB_PATH)
17
+ conn.row_factory = sqlite3.Row
18
+ cursor = conn.cursor()
19
+
20
+ result = None
21
+ if num:
22
+ cursor.execute("SELECT * FROM users WHERE phone = ?", (num,))
23
+ result = cursor.fetchone()
24
+ elif id:
25
+ cursor.execute("SELECT * FROM users WHERE user_id = ?", (id,))
26
+ result = cursor.fetchone()
27
+
28
+ conn.close()
29
+
30
+ if result:
31
+ return {
32
+ "status": "success",
33
+ "data": dict(result)
34
+ }
35
+ return {"status": "error", "message": "Data nahi mila!"}
36
+
37
+ if __name__ == "__main__":
38
+ import uvicorn
39
+ uvicorn.run(app, host="0.0.0.0", port=7860)