-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.txt
More file actions
191 lines (177 loc) · 5.37 KB
/
app.txt
File metadata and controls
191 lines (177 loc) · 5.37 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
from flask import Flask, request, render_template_string
import requests
from apscheduler.schedulers.background import BackgroundScheduler
import pytz
app = Flask(__name__)
# Define the LINE Notify token (replace with your own token)
LINE_NOTIFY_TOKEN = 'ymRbTJP3GwNeaFd3K6KI37Budn8026qOuiKzTbqswL0' # Replace with your actual token
# Define the HTML template for the form with improved styling
form_template = '''
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Workload Tracker</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f9;
color: #333;
margin: 0;
padding: 0;
}
h1 {
color: #007BFF;
}
.container {
width: 80%;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
label {
display: block;
margin-bottom: 8px;
font-weight: bold;
}
input[type="text"], textarea {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: 1px solid #ddd;
border-radius: 4px;
}
input[type="submit"] {
background-color: #007BFF;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #0056b3;
}
.response {
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>Enter Workload Information</h1>
<form action="/submit" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<label for="workload">Workload:</label>
<textarea id="workload" name="workload" rows="10" required></textarea>
<input type="submit" value="Submit">
</form>
</div>
</body>
</html>
'''
# Store workload data
workload_data = []
# Initialize the scheduler
scheduler = BackgroundScheduler()
def send_line_notify(message):
headers = {
'Authorization': f'Bearer {LINE_NOTIFY_TOKEN}',
}
payload = {'message': message}
try:
response = requests.post('https://notify-api.line.me/api/notify', headers=headers, params=payload)
print(f'Sent to LINE: {response.status_code}, {response.text}') # Debugging line
except Exception as e:
print(f'Error sending LINE notification: {e}')
@app.route('/')
def index():
return render_template_string(form_template)
@app.route('/submit', methods=['POST'])
def submit():
name = request.form['name']
workload = request.form['workload']
message = f"Name: *{name}*\nWorkload: {workload}"
# Format the latest workload message with better styling
return_message = f"""
<html>
<head>
<style>
body {{
font-family: Arial, sans-serif;
background-color: #f4f4f9;
color: #333;
margin: 0;
padding: 0;
}}
.container {{
width: 80%;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}}
h1 {{
color: #007BFF;
text-align: center;
}}
p {{
font-size: 16px;
line-height: 1.6;
}}
.details {{
margin: 20px 0;
padding: 10px;
background-color: #e9ecef;
border-radius: 4px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}}
.details h2 {{
color: #007BFF;
margin-top: 0;
}}
</style>
</head>
<body>
<div class="container">
<h1>Data Received!</h1>
<p>Your workload information has been successfully submitted. Here's the latest entry:</p>
<div class="details">
<h2>Latest Workload Submission</h2>
<p><strong>Name:</strong> {name}</p>
<p><strong>Workload:</strong><br>{workload.replace('\n', '<br>')}</p>
</div>
<p>We will notify you at 17:30 GMT+7.</p>
</div>
</body>
</html>
"""
# Store the workload data
workload_data.append(message)
# Print workload data for debugging
print(message)
# Return the styled response
return return_message
def job():
# Send a separate message for each workload entry
for workload in workload_data:
send_line_notify(workload)
# Clear the workload data after sending
workload_data.clear()
# Schedule the job at 17:30 GMT+7 every day
def schedule_job():
tz = pytz.timezone('Asia/Bangkok')
scheduler.add_job(job, 'cron', hour=11, minute=50, timezone=tz)
# Start the scheduler
scheduler.start()
schedule_job()
if __name__ == '__main__':
app.run(debug=True)