File size: 1,567 Bytes
1d5c031
0d48dbc
1d5c031
2212909
1d5c031
 
2212909
0d48dbc
2212909
1d5c031
3d6ff69
1d5c031
2212909
1d5c031
 
 
 
 
 
 
3d6ff69
1d5c031
 
2212909
3d6ff69
2212909
1d5c031
2212909
 
1d5c031
 
 
 
 
 
 
 
 
2212909
1d5c031
 
 
 
 
2212909
1d5c031
 
 
 
 
 
 
 
2212909
 
1d5c031
2212909
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

import os
import sqlite3
from fastapi import FastAPI, HTTPException
from huggingface_hub import hf_hub_download

app = FastAPI(title="Alien X OSINT API")

# Secret se token uthana
HF_TOKEN = os.environ.get("HF_TOKEN")

def get_db():
    print("⏳ Downloading database...")
    db_path = hf_hub_download(
        repo_id="Watchhrr/Pakistan-Master-Vault",
        filename="Pakistan_Master_Vault.db",
        repo_type="dataset",
        token=HF_TOKEN
    )
    return db_path

DB_FILE = get_db()

@app.get("/")
def home():
    return {"message": "🚀 Alien X OSINT API is Live!", "usage": "/search?pnum=92xxx"}

@app.get("/search")
def search(pnum: str = None, cnic: str = None):
    try:
        conn = sqlite3.connect(DB_FILE)
        cursor = conn.cursor()
        
        if pnum:
            cursor.execute("SELECT * FROM vault WHERE pnum = ?", (pnum,))
        elif cnic:
            cursor.execute("SELECT * FROM vault WHERE cnic = ?", (cnic,))
        else:
            raise HTTPException(status_code=400, detail="Provide pnum or cnic")
            
        row = cursor.fetchone()
        conn.close()
        
        if row:
            return {
                "status": "success",
                "data": {
                    "pnum": row[0],
                    "cnic": row[1],
                    "name": row[2],
                    "address": row[3],
                    "source": row[4]
                }
            }
        return {"status": "not_found"}
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))