Spaces:
Paused
Paused
| import sqlite3 | |
| import os | |
| from fastapi import FastAPI, HTTPException | |
| from fastapi.responses import FileResponse | |
| app = FastAPI() | |
| DB_PATH = "osint_master_66m.db" | |
| def home(): | |
| return {"status": "online", "records": "66.2M", "info": "OSINT API Live"} | |
| 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} | |
| def download(fn: str): | |
| return FileResponse(fn) | |