|
from fastapi import FastAPI, Form |
|
from fastapi.responses import HTMLResponse |
|
import requests |
|
import json |
|
import uvicorn |
|
|
|
app = FastAPI() |
|
|
|
@app.get("/", response_class=HTMLResponse) |
|
async def home(): |
|
return """ |
|
<!DOCTYPE html> |
|
<html> |
|
<head> |
|
<title>μ΄λ©μΌ μΉν
μ μ‘ μμ€ν
</title> |
|
<style> |
|
body { font-family: Arial, sans-serif; margin: 40px; } |
|
.container { max-width: 600px; margin: 0 auto; } |
|
input[type="email"] { width: 100%; padding: 8px; margin: 10px 0; } |
|
button { padding: 10px 20px; background: #007bff; color: white; border: none; cursor: pointer; } |
|
#result { margin-top: 20px; white-space: pre-wrap; } |
|
</style> |
|
</head> |
|
<body> |
|
<div class="container"> |
|
<h1>μ΄λ©μΌ μΉν
μ μ‘ μμ€ν
</h1> |
|
<form id="emailForm"> |
|
<input type="email" id="email" placeholder="μ΄λ©μΌ μ£Όμλ₯Ό μ
λ ₯νμΈμ" required> |
|
<button type="submit">μ μ‘</button> |
|
</form> |
|
<div id="result"></div> |
|
</div> |
|
<script> |
|
document.getElementById('emailForm').addEventListener('submit', async (e) => { |
|
e.preventDefault(); |
|
const email = document.getElementById('email').value; |
|
const resultDiv = document.getElementById('result'); |
|
|
|
try { |
|
const response = await fetch('/send-email', { |
|
method: 'POST', |
|
headers: { |
|
'Content-Type': 'application/x-www-form-urlencoded', |
|
}, |
|
body: `email=${encodeURIComponent(email)}` |
|
}); |
|
|
|
const result = await response.text(); |
|
resultDiv.textContent = result; |
|
} catch (error) { |
|
resultDiv.textContent = `μ€λ₯ λ°μ: ${error.message}`; |
|
} |
|
}); |
|
</script> |
|
</body> |
|
</html> |
|
""" |
|
|
|
@app.post("/send-email") |
|
async def send_email(email: str = Form(...)): |
|
webhook_url = "https://connect.pabbly.com/workflow/sendwebhookdata/IjU3NjYwNTZmMDYzMDA0M2M1MjZiNTUzMzUxMzUi_pc" |
|
|
|
payload = { |
|
"email": email |
|
} |
|
|
|
try: |
|
response = requests.post(webhook_url, json=payload) |
|
|
|
if response.status_code == 200: |
|
try: |
|
result = response.json() |
|
return f"μ±κ³΅!\nμλ΅ λ°μ΄ν°: {json.dumps(result, indent=2, ensure_ascii=False)}" |
|
except json.JSONDecodeError: |
|
return f"μ±κ³΅!\nμλ΅ λ΄μ©: {response.text}" |
|
else: |
|
return f"μ€λ₯ λ°μ. μν μ½λ: {response.status_code}\nμλ΅ λ΄μ©: {response.text}" |
|
|
|
except requests.exceptions.RequestException as e: |
|
return f"μμ² μ€ μ€λ₯ λ°μ: {str(e)}" |
|
|
|
if __name__ == "__main__": |
|
uvicorn.run(app, host="127.0.0.1", port=8000) |