Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Path, HTTPException
|
| 2 |
+
from fastapi.responses import JSONResponse
|
| 3 |
+
import subprocess
|
| 4 |
+
import json
|
| 5 |
+
import os
|
| 6 |
+
import requests
|
| 7 |
+
import re
|
| 8 |
+
import httpx
|
| 9 |
+
|
| 10 |
+
app = FastAPI()
|
| 11 |
+
|
| 12 |
+
@app.get("/api/{email}")
|
| 13 |
+
async def email_api(email: str = Path(...)):
|
| 14 |
+
try:
|
| 15 |
+
process = subprocess.Popen(['ghunt', 'email', '--json', f'{email}.json', email], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
| 16 |
+
process.wait()
|
| 17 |
+
if os.path.exists(f'{email}.json'):
|
| 18 |
+
with open(f'{email}.json', 'r') as file:
|
| 19 |
+
email_data = json.load(file)
|
| 20 |
+
os.remove(f'{email}.json')
|
| 21 |
+
return email_data
|
| 22 |
+
else:
|
| 23 |
+
raise HTTPException(status_code=404, detail="Email data not found")
|
| 24 |
+
except subprocess.CalledProcessError:
|
| 25 |
+
raise HTTPException(status_code=500, detail="Failed to execute command")
|
| 26 |
+
|