aiqtech commited on
Commit
5d67131
ยท
verified ยท
1 Parent(s): 7b6c237

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -76
app.py CHANGED
@@ -1,83 +1,50 @@
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)
 
1
+ from flask import Flask, request, render_template_string
 
2
  import requests
3
  import json
 
4
 
5
+ app = Flask(__name__)
6
 
7
+ # HTML ํ…œํ”Œ๋ฆฟ
8
+ HTML_TEMPLATE = '''
9
+ <!DOCTYPE html>
10
+ <html>
11
+ <head>
12
+ <title>์ด๋ฉ”์ผ ์ „์†ก</title>
13
+ <meta charset="utf-8">
14
+ </head>
15
+ <body>
16
+ <h1>์ด๋ฉ”์ผ ์›นํ›… ์ „์†ก</h1>
17
+ <form method="POST">
18
+ <input type="email" name="email" placeholder="์ด๋ฉ”์ผ ์ฃผ์†Œ ์ž…๋ ฅ" required>
19
+ <input type="submit" value="์ „์†ก">
20
+ </form>
21
+ {% if result %}
22
+ <p>{{ result }}</p>
23
+ {% endif %}
24
+ </body>
25
+ </html>
26
+ '''
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
+ @app.route('/', methods=['GET', 'POST'])
29
+ def home():
30
+ result = None
31
+ if request.method == 'POST':
32
+ email = request.form['email']
33
+ webhook_url = "https://connect.pabbly.com/workflow/sendwebhookdata/IjU3NjYwNTZmMDYzMDA0M2M1MjZiNTUzMzUxMzUi_pc"
 
 
 
 
34
 
35
+ try:
36
+ response = requests.post(webhook_url, json={"email": email})
37
+ if response.status_code == 200:
38
+ try:
39
+ result = f"์„ฑ๊ณต!\n{json.dumps(response.json(), indent=2, ensure_ascii=False)}"
40
+ except:
41
+ result = f"์„ฑ๊ณต!\n{response.text}"
42
+ else:
43
+ result = f"์˜ค๋ฅ˜: {response.status_code}\n{response.text}"
44
+ except Exception as e:
45
+ result = f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
46
+
47
+ return render_template_string(HTML_TEMPLATE, result=result)
48
 
49
+ if __name__ == '__main__':
50
+ app.run(debug=True, port=7860)