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)