fdfdfef / app.py
aiqtech's picture
Create app.py
6d854f4 verified
raw
history blame
3.04 kB
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)