osint-api-66m / app.py
Watchhrr's picture
Upload app.py with huggingface_hub
29baea1 verified
Raw
History Blame Contribute Delete
1.14 kB
import sqlite3
import os
from fastapi import FastAPI, HTTPException
from fastapi.responses import FileResponse
app = FastAPI()
DB_PATH = "osint_master_66m.db"
@app.get("/")
def home():
return {"status": "online", "records": "66.2M", "info": "OSINT API Live"}
@app.get("/search")
def search(domain: str):
domain = domain.lower().strip().replace("www.", "")
if not os.path.exists(DB_PATH):
return {"error": "DB initializing or not found"}
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
cursor.execute("SELECT data FROM logs WHERE domain = ?", (domain,))
results = [row[0] for row in cursor.fetchall()]
conn.close()
if not results:
return {"status": "not_found", "count": 0}
if len(results) > 50:
fn = f"results_{domain}.txt"
with open(fn, "w", encoding='utf-8') as f:
f.write('\n'.join(results))
return {"status": "file", "count": len(results), "download_url": f"/download/{fn}"}
return {"status": "success", "count": len(results), "data": results}
@app.get("/download/{fn}")
def download(fn: str):
return FileResponse(fn)