DinoPLayZ commited on
Commit
9bb4423
·
verified ·
1 Parent(s): 19ae872

Formatted the New Event Email Format

Browse files
Files changed (1) hide show
  1. main.py +129 -25
main.py CHANGED
@@ -184,32 +184,136 @@ def send_event_alerts(events):
184
  if not events:
185
  return
186
 
187
- msg = f"📢 <b>{len(events)} New BIP Event Found!</b><br><br>"
188
-
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  for i, ev in enumerate(events, 1):
190
- # Format start date
191
- start = ev.get('start_date', '')
192
- if start:
193
- start = datetime.strptime(start, "%Y-%m-%d").strftime("%d-%m-%Y")
194
-
195
- # Format end date
196
- end = ev.get('end_date', '')
197
- if end:
198
- end = datetime.strptime(end, "%Y-%m-%d").strftime("%d-%m-%Y")
199
-
200
- msg += (
201
- f"<b>{ev.get('event_code', '-')} - "
202
- f"{ev.get('event_name', 'Unknown')}</b><br><br>"
203
- f"{ev.get('event_category', '-')}<br><br>"
204
- f"{start} to {end}<br><br>"
205
- f"{ev.get('location', '-')}<br><br>"
206
- f"{ev.get('status', '-')}<br><br>"
207
- f"Seats: Max {ev.get('maximum_count', '-')} | "
208
- f"Applied {ev.get('applied_count', '-')}<br>"
209
- f"<a href='{ev.get('web_url', '#')}'>View Event Here</a><br>"
210
- f"<hr>"
211
- )
212
- send_email_message("📢 New BIP Event(s) Found!", msg, is_html=True, recipient=EVENT_EMAIL_RECIPIENT)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
 
214
 
215
  # ==============================================================================
 
184
  if not events:
185
  return
186
 
187
+ msg = """
188
+ <div style="font-family: Arial, sans-serif; background-color: #f4f6f9; padding: 20px;">
189
+ <div style="max-width: 600px; margin: 0 auto; background: #ffffff; border-radius: 8px;
190
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1); overflow: hidden;">
191
+
192
+ <!-- Centered Heading ONLY -->
193
+ <div style="background-color: #0056b3; color: #ffffff; padding: 15px 20px;
194
+ font-size: 18px; font-weight: bold; text-align: center;">
195
+ 📢 Event Details
196
+ </div>
197
+
198
+ <!-- Content (LEFT ALIGNED) -->
199
+ <div style="padding: 20px;">
200
+ """
201
+
202
  for i, ev in enumerate(events, 1):
203
+
204
+ # Date formatting
205
+ from datetime import datetime
206
+
207
+ def format_date(date_str):
208
+ try:
209
+ dt = datetime.strptime(date_str, "%Y-%m-%d")
210
+ return f"<span style='font-weight:bold;'>{dt.strftime('%d-%m')}</span>-{dt.strftime('%Y')}"
211
+ except:
212
+ return date_str
213
+
214
+ start = format_date(ev.get("start_date", "")) if ev.get("start_date") else ""
215
+ end = format_date(ev.get("end_date", "")) if ev.get("end_date") else ""
216
+
217
+ date_str = f"{start} to {end}" if start and end else (start or end or "-")
218
+
219
+ # Highlight last 3 digits of code
220
+ code = ev.get("event_code", "-")
221
+ if len(code) >= 3:
222
+ highlighted_code = code[:-3] + f"<span style='font-weight:bold; color:#dc3545;'>{code[-3:]}</span>"
223
+ else:
224
+ highlighted_code = code
225
+
226
+ # Count values
227
+ max_count = ev.get("max_count", 0)
228
+ applied = ev.get("applied_count", 0)
229
+ balance = max_count - applied
230
+
231
+ msg += f"""
232
+ <table style="width: 100%; border-collapse: collapse;
233
+ margin-bottom: 25px; font-size: 15px;
234
+ color: #333333; text-align: left;">
235
+
236
+ <tr>
237
+ <td style="padding: 8px 0; font-weight: bold; width: 35%;">Code</td>
238
+ <td style="padding: 8px 0; width: 5%;">:</td>
239
+ <td style="padding: 8px 0; width: 60%;">{highlighted_code}</td>
240
+ </tr>
241
+
242
+ <tr>
243
+ <td style="padding: 8px 0; font-weight: bold;">Organizer</td>
244
+ <td style="padding: 8px 0;">:</td>
245
+ <td style="padding: 8px 0;">{ev.get('organizer', '-')}</td>
246
+ </tr>
247
+
248
+ <tr>
249
+ <td style="padding: 8px 0; font-weight: bold;">Date</td>
250
+ <td style="padding: 8px 0;">:</td>
251
+ <td style="padding: 8px 0;">{date_str}</td>
252
+ </tr>
253
+
254
+ <tr>
255
+ <td style="padding: 8px 0; font-weight: bold;">Category</td>
256
+ <td style="padding: 8px 0;">:</td>
257
+ <td style="padding: 8px 0;">{ev.get('event_category', '-')}</td>
258
+ </tr>
259
+
260
+ <tr>
261
+ <td style="padding: 8px 0; font-weight: bold;">Location</td>
262
+ <td style="padding: 8px 0;">:</td>
263
+ <td style="padding: 8px 0;">{ev.get('location', '-')}</td>
264
+ </tr>
265
+
266
+ <tr>
267
+ <td style="padding: 12px 0; font-weight: bold;">Count</td>
268
+ <td style="padding: 12px 0;">:</td>
269
+ <td style="padding: 12px 0;">
270
+ Max: <b>{max_count}</b> |
271
+ Balance: <b>{balance}</b> |
272
+ Applied: <b>{applied}</b>
273
+ </td>
274
+ </tr>
275
+
276
+ <tr>
277
+ <td style="padding: 8px 0; font-weight: bold;">Logger URL</td>
278
+ <td style="padding: 8px 0;">:</td>
279
+ <td style="padding: 8px 0;">
280
+ <a href="https://bip.bitsathy.ac.in/nova/resources/student-achievement-loggers/new"
281
+ style="color: #0056b3; text-decoration: none;">
282
+ Link
283
+ </a>
284
+ </td>
285
+ </tr>
286
+
287
+ <tr>
288
+ <td style="padding: 8px 0; font-weight: bold;">View Link</td>
289
+ <td style="padding: 8px 0;">:</td>
290
+ <td style="padding: 8px 0;">
291
+ <a href="{ev.get('web_url', '#')}"
292
+ style="color: #0056b3; text-decoration: none;">
293
+ View Event Here
294
+ </a>
295
+ </td>
296
+ </tr>
297
+
298
+ </table>
299
+ """
300
+
301
+ if i < len(events):
302
+ msg += "<hr style='border: none; border-top: 1px solid #e0e0e0; margin: 20px 0;'>"
303
+
304
+ msg += """
305
+ </div>
306
+
307
+ <div style="background-color: #f8f9fa; padding: 15px 20px; text-align: center;
308
+ font-size: 12px; color: #777777; border-top: 1px solid #e0e0e0;">
309
+ Automated Notification from BIP Tracker
310
+ </div>
311
+
312
+ </div>
313
+ </div>
314
+ """
315
+
316
+ send_email_message("New Event Added", msg, is_html=True, recipient=EVENT_EMAIL_RECIPIENT)
317
 
318
 
319
  # ==============================================================================