Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, Form
|
2 |
+
from fastapi.responses import HTMLResponse
|
3 |
+
import requests
|
4 |
+
import json
|
5 |
+
import uvicorn
|
6 |
+
|
7 |
+
app = FastAPI()
|
8 |
+
|
9 |
+
@app.get("/", response_class=HTMLResponse)
|
10 |
+
async def home():
|
11 |
+
return """
|
12 |
+
<!DOCTYPE html>
|
13 |
+
<html>
|
14 |
+
<head>
|
15 |
+
<title>์ด๋ฉ์ผ ์นํ
์ ์ก ์์คํ
</title>
|
16 |
+
<style>
|
17 |
+
body { font-family: Arial, sans-serif; margin: 40px; }
|
18 |
+
.container { max-width: 600px; margin: 0 auto; }
|
19 |
+
input[type="email"] { width: 100%; padding: 8px; margin: 10px 0; }
|
20 |
+
button { padding: 10px 20px; background: #007bff; color: white; border: none; cursor: pointer; }
|
21 |
+
#result { margin-top: 20px; white-space: pre-wrap; }
|
22 |
+
</style>
|
23 |
+
</head>
|
24 |
+
<body>
|
25 |
+
<div class="container">
|
26 |
+
<h1>์ด๋ฉ์ผ ์นํ
์ ์ก ์์คํ
</h1>
|
27 |
+
<form id="emailForm">
|
28 |
+
<input type="email" id="email" placeholder="์ด๋ฉ์ผ ์ฃผ์๋ฅผ ์
๋ ฅํ์ธ์" required>
|
29 |
+
<button type="submit">์ ์ก</button>
|
30 |
+
</form>
|
31 |
+
<div id="result"></div>
|
32 |
+
</div>
|
33 |
+
<script>
|
34 |
+
document.getElementById('emailForm').addEventListener('submit', async (e) => {
|
35 |
+
e.preventDefault();
|
36 |
+
const email = document.getElementById('email').value;
|
37 |
+
const resultDiv = document.getElementById('result');
|
38 |
+
|
39 |
+
try {
|
40 |
+
const response = await fetch('/send-email', {
|
41 |
+
method: 'POST',
|
42 |
+
headers: {
|
43 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
44 |
+
},
|
45 |
+
body: `email=${encodeURIComponent(email)}`
|
46 |
+
});
|
47 |
+
|
48 |
+
const result = await response.text();
|
49 |
+
resultDiv.textContent = result;
|
50 |
+
} catch (error) {
|
51 |
+
resultDiv.textContent = `์ค๋ฅ ๋ฐ์: ${error.message}`;
|
52 |
+
}
|
53 |
+
});
|
54 |
+
</script>
|
55 |
+
</body>
|
56 |
+
</html>
|
57 |
+
"""
|
58 |
+
|
59 |
+
@app.post("/send-email")
|
60 |
+
async def send_email(email: str = Form(...)):
|
61 |
+
webhook_url = "https://connect.pabbly.com/workflow/sendwebhookdata/IjU3NjYwNTZmMDYzMDA0M2M1MjZiNTUzMzUxMzUi_pc"
|
62 |
+
|
63 |
+
payload = {
|
64 |
+
"email": email
|
65 |
+
}
|
66 |
+
|
67 |
+
try:
|
68 |
+
response = requests.post(webhook_url, json=payload)
|
69 |
+
|
70 |
+
if response.status_code == 200:
|
71 |
+
try:
|
72 |
+
result = response.json()
|
73 |
+
return f"์ฑ๊ณต!\n์๋ต ๋ฐ์ดํฐ: {json.dumps(result, indent=2, ensure_ascii=False)}"
|
74 |
+
except json.JSONDecodeError:
|
75 |
+
return f"์ฑ๊ณต!\n์๋ต ๋ด์ฉ: {response.text}"
|
76 |
+
else:
|
77 |
+
return f"์ค๋ฅ ๋ฐ์. ์ํ ์ฝ๋: {response.status_code}\n์๋ต ๋ด์ฉ: {response.text}"
|
78 |
+
|
79 |
+
except requests.exceptions.RequestException as e:
|
80 |
+
return f"์์ฒญ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
81 |
+
|
82 |
+
if __name__ == "__main__":
|
83 |
+
uvicorn.run(app, host="127.0.0.1", port=8000)
|