File size: 3,041 Bytes
6d854f4 |
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
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) |