Ninad077 commited on
Commit
9a77024
·
verified ·
1 Parent(s): 14b2dbc

Upload 4 files

Browse files
Files changed (2) hide show
  1. ap.py +537 -0
  2. app.py +107 -410
ap.py ADDED
@@ -0,0 +1,537 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import smtplib
3
+ from email.mime.multipart import MIMEMultipart
4
+ from email.mime.text import MIMEText
5
+ from email.mime.base import MIMEBase
6
+ from email import encoders
7
+ import requests
8
+ import base64
9
+
10
+ # Encode the image to Base64
11
+ def get_base64_image(image_path):
12
+ with open(image_path, "rb") as image_file:
13
+ return base64.b64encode(image_file.read()).decode()
14
+
15
+
16
+
17
+ # Define your Slack email addresses and webhook URLs
18
+ Slack_email_addresses = {
19
+ 'ninadmandavkar': '[email protected]',
20
+ 'Priyanshi Nahata': '[email protected]',
21
+ 'kiran jadhav': '[email protected]',
22
+ 'Bhavin Parmar': '[email protected]',
23
+ 'RJ': '[email protected]',
24
+ 'VS': '[email protected]',
25
+ 'Roshani Mohan': '[email protected]',
26
+ 'omkarsp': '[email protected]',
27
+ 'Abhilash Sawant': '[email protected]',
28
+ 'Hemant Yadav': '[email protected]',
29
+ 'SandeeP Salunkhe': '[email protected]',
30
+ 'Abhimanyu':'[email protected]',
31
+ 'Sid': '[email protected]',
32
+ 'chetanpatole': '[email protected]',
33
+ 'Shweta Kanungo': '[email protected]',
34
+ 'chandnichaurasia': '[email protected]',
35
+ 'Rasika': '[email protected]',
36
+ 'Bhushan Khapare': '[email protected]',
37
+ 'daily-alerts-for-unsubscribed-companies': 'daily-alerts-for-unsu-aaaanufptnpzgjtmknapgi45oq@gofynd.slack.com',
38
+ 'finance_team_internal': 'finance_team_internal-aaaabrz6gd5km3hjwxs7saxa4a@gofynd.slack.com',
39
+ 'valyx-fynd-poc': '[email protected]',
40
+ 'valyx_auto_invoices': '[email protected]'
41
+ }
42
+
43
+ gmail_addresses = {
44
+ 'ninadmandavkar': '[email protected]',
45
+ 'omkarsp': '[email protected]',
46
+ 'Priyanshi Nahata': '[email protected]',
47
+ 'kiran jadhav': '[email protected]',
48
+ 'Bhavin Parmar': '[email protected]',
49
+ 'RJ': '[email protected]',
50
+ 'VS': '[email protected]',
51
+ 'Roshani Mohan': '[email protected]',
52
+ 'Abhilash Sawant': '[email protected]',
53
+ 'Hemant Yadav': '[email protected]',
54
+ 'SandeeP Salunkhe': '[email protected]',
55
+ 'Abhimanyu':'[email protected]',
56
+ 'Sid': '[email protected]',
57
+ 'chetanpatole': '[email protected]',
58
+ 'Shweta Kanungo': '[email protected]',
59
+ 'chandnichaurasia': '[email protected]',
60
+ 'Rasika': '[email protected]',
61
+ 'Bhushan Khapare': '[email protected]',
62
+ 'daily-alerts-for-unsubscribed-companies': 'daily-alerts-for-unsu-aaaanufptnpzgjtmknapgi45oq@gofynd.slack.com',
63
+ 'finance_team_internal': 'finance_team_internal-aaaabrz6gd5km3hjwxs7saxa4a@gofynd.slack.com',
64
+ 'valyx-fynd-poc': '[email protected]',
65
+ 'valyx_auto_invoices': '[email protected]'
66
+
67
+ }
68
+
69
+ Webhook_urls = {
70
+ 'ninadmandavkar': 'https://hooks.slack.com/services/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',
71
+ 'Priyanshi Nahata': 'https://hooks.slack.com/services/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',
72
+ 'kiran jadhav': 'https://hooks.slack.com/services/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',
73
+ 'Bhavin Parmar': 'https://hooks.slack.com/services/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',
74
+ 'RJ': 'https://hooks.slack.com/services/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',
75
+ 'VS': 'https://hooks.slack.com/services/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',
76
+ 'Roshani Mohan': 'https://hooks.slack.com/services/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',
77
+ 'omkarsp': 'https://hooks.slack.com/services/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',
78
+ 'Abhilash Sawant': 'https://hooks.slack.com/services/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',
79
+ 'Hemant Yadav': 'https://hooks.slack.com/services/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',
80
+ 'SandeeP Salunkhe': 'https://hooks.slack.com/services/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',
81
+ 'Abhimanyu':'https://hooks.slack.com/services/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',
82
+ 'Sid': 'https://hooks.slack.com/services/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',
83
+ 'chetanpatole': 'https://hooks.slack.com/services/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',
84
+ 'Shweta Kanungo': 'https://hooks.slack.com/services/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',
85
+ 'chandnichaurasia': 'https://hooks.slack.com/services/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',
86
+ 'Rasika': 'https://hooks.slack.com/services/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',
87
+ 'Bhushan Khapare': 'https://hooks.slack.com/services/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',
88
+ 'daily-alerts-for-unsubscribed-companies': 'https://hooks.slack.com/services/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',
89
+ 'finance_team_internal': 'https://hooks.slack.com/services/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',
90
+ 'valyx-fynd-poc': 'https://hooks.slack.com/services/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',
91
+ 'valyx_auto_invoices': 'https://hooks.slack.com/services/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'
92
+ }
93
+
94
+ # Define your email server details
95
+ EMAIL_HOST = 'smtp.gmail.com'
96
+ EMAIL_PORT = 587
97
+ EMAIL_HOST_USER = '[email protected]'
98
+ EMAIL_HOST_PASSWORD = 'vxay jiss cctw lsdo'
99
+
100
+ def send_message_via_email(message, email_address, files, subject=None, body=None):
101
+ try:
102
+ # Set up the server
103
+ server = smtplib.SMTP(EMAIL_HOST, EMAIL_PORT)
104
+ server.starttls()
105
+ server.login(EMAIL_HOST_USER, EMAIL_HOST_PASSWORD)
106
+
107
+ # Create the email
108
+ msg = MIMEMultipart()
109
+ msg['From'] = EMAIL_HOST_USER
110
+ msg['To'] = email_address
111
+ msg['Subject'] = subject if subject else "🚨 Alerter"
112
+
113
+ # Attach the message body
114
+ msg.attach(MIMEText(body if body else message, 'plain'))
115
+
116
+ # Attach each file if provided
117
+ if files:
118
+ for uploaded_file in files:
119
+ part = MIMEBase('application', 'octet-stream')
120
+ part.set_payload(uploaded_file.read())
121
+ encoders.encode_base64(part)
122
+ part.add_header('Content-Disposition', f'attachment; filename={uploaded_file.name}')
123
+ msg.attach(part)
124
+
125
+ # Send the email
126
+ server.sendmail(EMAIL_HOST_USER, email_address, msg.as_string())
127
+ server.quit()
128
+ return True, "Message sent successfully"
129
+ except Exception as e:
130
+ return False, str(e)
131
+
132
+ def send_message_via_webhook(message, webhook_url):
133
+ try:
134
+ payload = {
135
+ "text": message
136
+ }
137
+ response = requests.post(webhook_url, json=payload)
138
+ response.raise_for_status()
139
+ return True, "Message sent successfully"
140
+ except requests.exceptions.RequestException as e:
141
+ return False, str(e)
142
+
143
+ def main():
144
+
145
+ # Path to your image
146
+ image_path = "Designer (1).png"
147
+ base64_image = get_base64_image(image_path)
148
+
149
+ # Define the CSS for setting the background image
150
+ # background_image_css = f"""
151
+ # <style>
152
+ # .stApp {{
153
+ # background-image: url(data:image/png;base64,{base64_image});
154
+ # background-size: 100%;
155
+ # background-repeat: no-repeat;
156
+ # background-attachment: fixed;
157
+ # background-position: center;
158
+ # height: 100vh; /* Make sure the background covers the full viewport height */
159
+
160
+ # }}
161
+ # </style>
162
+ # """
163
+
164
+ # # Apply the CSS to the Streamlit app
165
+ # st.markdown(background_image_css, unsafe_allow_html=True)
166
+
167
+
168
+
169
+ html_subject = """
170
+ <html>
171
+ <head>
172
+ <style>
173
+ .button {
174
+ display: inline-block;
175
+ padding: 10px 20px;
176
+ border-radius: 12px;
177
+ background: linear-gradient(to bottom, #f8f9fa, #e0e0e0);
178
+ box-shadow:
179
+ 0 6px 12px rgba(0, 0, 0, 0.3),
180
+ 0 8px 16px rgba(0, 0, 0, 0.2),
181
+ inset 0 -2px 4px rgba(255, 255, 255, 0.6);
182
+ text-align: center;
183
+ position: relative;
184
+ transform: translateY(4px);
185
+ transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
186
+ cursor: pointer;
187
+ user-select: none;
188
+ }
189
+ .button:hover {
190
+ box-shadow:
191
+ 0 8px 16px rgba(0, 0, 0, 0.3),
192
+ 0 12px 24px rgba(0, 0, 0, 0.2);
193
+ transform: translateY(2px);
194
+ }
195
+ .button:active {
196
+ box-shadow:
197
+ 0 4px 8px rgba(0, 0, 0, 0.3),
198
+ 0 6px 12px rgba(0, 0, 0, 0.2);
199
+ transform: translateY(0);
200
+ }
201
+ </style>
202
+ </head>
203
+ <body>
204
+ <div class="button">
205
+ <h3 style="
206
+ font-size: 20px;
207
+ color: #ffffff;
208
+ background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9);
209
+ background-clip: text;
210
+ -webkit-background-clip: text;
211
+ text-fill-color: transparent;
212
+ -webkit-text-fill-color: transparent;
213
+ margin: 0;
214
+ text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
215
+ ">Write a Slack message</h3>
216
+ </div>
217
+ </body>
218
+ </html>
219
+ """
220
+
221
+
222
+
223
+ st.markdown(html_subject, unsafe_allow_html=True)
224
+ message = st.text_area("", "")
225
+
226
+
227
+ # File uploader widget with a unique key
228
+ html_subject = """
229
+ <html>
230
+ <head>
231
+ <style>
232
+ .button {
233
+ display: inline-block;
234
+ padding: 10px 20px;
235
+ border-radius: 12px;
236
+ background: linear-gradient(to bottom, #f8f9fa, #e0e0e0);
237
+ box-shadow:
238
+ 0 6px 12px rgba(0, 0, 0, 0.3),
239
+ 0 8px 16px rgba(0, 0, 0, 0.2),
240
+ inset 0 -2px 4px rgba(255, 255, 255, 0.6);
241
+ text-align: center;
242
+ position: relative;
243
+ transform: translateY(4px);
244
+ transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
245
+ cursor: pointer;
246
+ user-select: none;
247
+ }
248
+ .button:hover {
249
+ box-shadow:
250
+ 0 8px 16px rgba(0, 0, 0, 0.3),
251
+ 0 12px 24px rgba(0, 0, 0, 0.2);
252
+ transform: translateY(2px);
253
+ }
254
+ .button:active {
255
+ box-shadow:
256
+ 0 4px 8px rgba(0, 0, 0, 0.3),
257
+ 0 6px 12px rgba(0, 0, 0, 0.2);
258
+ transform: translateY(0);
259
+ }
260
+ </style>
261
+ </head>
262
+ <body>
263
+ <div class="button">
264
+ <h3 style="
265
+ font-size: 20px;
266
+ color: #ffffff;
267
+ background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9);
268
+ background-clip: text;
269
+ -webkit-background-clip: text;
270
+ text-fill-color: transparent;
271
+ -webkit-text-fill-color: transparent;
272
+ margin: 0;
273
+ text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
274
+ ">Upload documents</h3>
275
+ </div>
276
+ </body>
277
+ </html>
278
+ """
279
+
280
+
281
+ st.markdown(html_subject, unsafe_allow_html=True)
282
+ uploaded_file = st.file_uploader("", type=["pdf", "docx", "png", "jpeg", "xlsx", "csv", "json"], key="file_uploader", accept_multiple_files= True)
283
+
284
+ # Dropdown for channels/members
285
+ options = list(Slack_email_addresses.keys())
286
+ html_subject = """
287
+ <html>
288
+ <head>
289
+ <style>
290
+ .button {
291
+ display: inline-block;
292
+ padding: 10px 20px;
293
+ border-radius: 12px;
294
+ background: linear-gradient(to bottom, #f8f9fa, #e0e0e0);
295
+ box-shadow:
296
+ 0 6px 12px rgba(0, 0, 0, 0.3),
297
+ 0 8px 16px rgba(0, 0, 0, 0.2),
298
+ inset 0 -2px 4px rgba(255, 255, 255, 0.6);
299
+ text-align: center;
300
+ position: relative;
301
+ transform: translateY(4px);
302
+ transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
303
+ cursor: pointer;
304
+ user-select: none;
305
+ }
306
+ .button:hover {
307
+ box-shadow:
308
+ 0 8px 16px rgba(0, 0, 0, 0.3),
309
+ 0 12px 24px rgba(0, 0, 0, 0.2);
310
+ transform: translateY(2px);
311
+ }
312
+ .button:active {
313
+ box-shadow:
314
+ 0 4px 8px rgba(0, 0, 0, 0.3),
315
+ 0 6px 12px rgba(0, 0, 0, 0.2);
316
+ transform: translateY(0);
317
+ }
318
+ </style>
319
+ </head>
320
+ <body>
321
+ <div class="button">
322
+ <h3 style="
323
+ font-size: 20px;
324
+ color: #ffffff;
325
+ background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9);
326
+ background-clip: text;
327
+ -webkit-background-clip: text;
328
+ text-fill-color: transparent;
329
+ -webkit-text-fill-color: transparent;
330
+ margin: 0;
331
+ text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
332
+ ">Select channels/members</h3>
333
+ </div>
334
+ </body>
335
+ </html>
336
+ """
337
+
338
+
339
+ st.markdown(html_subject, unsafe_allow_html=True)
340
+ selection = st.multiselect("", options)
341
+
342
+ html_subject = """
343
+ <html>
344
+ <head>
345
+ <style>
346
+ .button {
347
+ display: inline-block;
348
+ padding: 10px 20px;
349
+ border-radius: 12px;
350
+ background: linear-gradient(to bottom, #f8f9fa, #e0e0e0);
351
+ box-shadow:
352
+ 0 6px 12px rgba(0, 0, 0, 0.3),
353
+ 0 8px 16px rgba(0, 0, 0, 0.2),
354
+ inset 0 -2px 4px rgba(255, 255, 255, 0.6);
355
+ text-align: center;
356
+ position: relative;
357
+ transform: translateY(4px);
358
+ transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
359
+ cursor: pointer;
360
+ user-select: none;
361
+ }
362
+ .button:hover {
363
+ box-shadow:
364
+ 0 8px 16px rgba(0, 0, 0, 0.3),
365
+ 0 12px 24px rgba(0, 0, 0, 0.2);
366
+ transform: translateY(2px);
367
+ }
368
+ .button:active {
369
+ box-shadow:
370
+ 0 4px 8px rgba(0, 0, 0, 0.3),
371
+ 0 6px 12px rgba(0, 0, 0, 0.2);
372
+ transform: translateY(0);
373
+ }
374
+ </style>
375
+ </head>
376
+ <body>
377
+ <div class="button">
378
+ <h3 style="
379
+ font-size: 20px;
380
+ color: #ffffff;
381
+ background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9);
382
+ background-clip: text;
383
+ -webkit-background-clip: text;
384
+ text-fill-color: transparent;
385
+ -webkit-text-fill-color: transparent;
386
+ margin: 0;
387
+ text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
388
+ ">Enter the subject(optional)</h3>
389
+ </div>
390
+ </body>
391
+ </html>
392
+ """
393
+
394
+
395
+ st.markdown(html_subject, unsafe_allow_html=True)
396
+ subject = st.text_input("", "",key ="subject_text_input")
397
+
398
+
399
+
400
+ html_subject = """
401
+ <html>
402
+ <head>
403
+ <style>
404
+ .button {
405
+ display: inline-block;
406
+ padding: 10px 20px;
407
+ border-radius: 12px;
408
+ background: linear-gradient(to bottom, #f8f9fa, #e0e0e0);
409
+ box-shadow:
410
+ 0 6px 12px rgba(0, 0, 0, 0.3),
411
+ 0 8px 16px rgba(0, 0, 0, 0.2),
412
+ inset 0 -2px 4px rgba(255, 255, 255, 0.6);
413
+ text-align: center;
414
+ position: relative;
415
+ transform: translateY(4px);
416
+ transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
417
+ cursor: pointer;
418
+ user-select: none;
419
+ }
420
+ .button:hover {
421
+ box-shadow:
422
+ 0 8px 16px rgba(0, 0, 0, 0.3),
423
+ 0 12px 24px rgba(0, 0, 0, 0.2);
424
+ transform: translateY(2px);
425
+ }
426
+ .button:active {
427
+ box-shadow:
428
+ 0 4px 8px rgba(0, 0, 0, 0.3),
429
+ 0 6px 12px rgba(0, 0, 0, 0.2);
430
+ transform: translateY(0);
431
+ }
432
+ </style>
433
+ </head>
434
+ <body>
435
+ <div class="button">
436
+ <h3 style="
437
+ font-size: 20px;
438
+ color: #ffffff;
439
+ background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9);
440
+ background-clip: text;
441
+ -webkit-background-clip: text;
442
+ text-fill-color: transparent;
443
+ -webkit-text-fill-color: transparent;
444
+ margin: 0;
445
+ text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
446
+ ">Enter the body (optional)</h3>
447
+ </div>
448
+ </body>
449
+ </html>
450
+ """
451
+
452
+
453
+ st.markdown(html_subject, unsafe_allow_html=True)
454
+ body = st.text_area("", "", key="body_text_area")
455
+
456
+
457
+ button_styles = """
458
+ <style>
459
+ div.stButton > button {
460
+ color: #ffffff; /* Text color */
461
+ font-size: 30px;
462
+ background-image: linear-gradient(to right, #800000, #ff0000); /* Maroon to light red gradient */
463
+ border: none;
464
+ padding: 10px 20px;
465
+ cursor: pointer;
466
+ border-radius: 15px;
467
+ display: inline-block;
468
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 8px 15px rgba(0, 0, 0, 0.1); /* Box shadow */
469
+ transition: all 0.3s ease; /* Smooth transition on hover */
470
+ }
471
+ div.stButton > button:hover {
472
+ background-color: #00ff00; /* Hover background color */
473
+ color: #ff0000; /* Hover text color */
474
+ box-shadow: 0 6px 10px rgba(0, 0, 0, 0.2), 0 12px 20px rgba(0, 0, 0, 0.2); /* Box shadow on hover */
475
+ }
476
+ </style>
477
+ """
478
+ st.markdown(button_styles, unsafe_allow_html=True)
479
+
480
+ col1, col2 = st.columns([0.125, 0.5])
481
+ with col1:
482
+ if st.button("Send to Slack"):
483
+ if not message and not uploaded_file:
484
+ st.error("Please enter a message or upload a document before sending.")
485
+ return
486
+
487
+ if not selection:
488
+ st.error("Please select at least one channel or member")
489
+ return
490
+
491
+ for item in selection:
492
+ if uploaded_file:
493
+ # Send the document via email
494
+ email_address = Slack_email_addresses.get(item)
495
+ if email_address:
496
+ success, response_message = send_message_via_email(message, email_address, uploaded_file, subject, body)
497
+ # if success:
498
+ # st.success(f"Document sent to {item} via email.")
499
+ # else:
500
+ # st.error(f"Failed to send document to {item}: {response_message}")
501
+ else:
502
+ st.error(f"No email address found for {item}.")
503
+ elif message:
504
+ # Send the message via Slack webhook
505
+ webhook_url = Webhook_urls.get(item)
506
+ if webhook_url:
507
+ success, response_message = send_message_via_webhook(message, webhook_url)
508
+ # if success:
509
+ # st.success(f"Message sent to {item} via Slack webhook.")
510
+ # else:
511
+ # st.error(f"Failed to send message to {item}: {response_message}")
512
+ else:
513
+ st.error(f"No webhook URL found for {item}.")
514
+
515
+ with col2:
516
+ if st.button("Send to Gmail"):
517
+ if not message and not uploaded_file:
518
+ st.error("Please enter a message or upload a document before sending.")
519
+ return
520
+
521
+ if not selection:
522
+ st.error("Please select at least one channel or member")
523
+ return
524
+
525
+ for item in selection:
526
+ email_address = gmail_addresses.get(item)
527
+ if email_address:
528
+ success, response_message = send_message_via_email(message, email_address, uploaded_file, subject, body)
529
+ # if success:
530
+ # st.success(f"Message sent to {item} via Gmail.")
531
+ # else:
532
+ # st.error(f"Failed to send message to {item}: {response_message}")
533
+ else:
534
+ st.error(f"No Gmail address found for {item}.")
535
+
536
+ if __name__ == "__main__":
537
+ main()
app.py CHANGED
@@ -1,95 +1,11 @@
1
  import streamlit as st
 
2
  import smtplib
3
- from email.mime.multipart import MIMEMultipart
4
  from email.mime.text import MIMEText
5
- from email.mime.base import MIMEBase
6
- from email import encoders
7
- import requests
8
- import base64
9
-
10
- # Encode the image to Base64
11
- def get_base64_image(image_path):
12
- with open(image_path, "rb") as image_file:
13
- return base64.b64encode(image_file.read()).decode()
14
-
15
-
16
-
17
- # Define your Slack email addresses and webhook URLs
18
- Slack_email_addresses = {
19
- 'ninadmandavkar': '[email protected]',
20
- 'Priyanshi Nahata': '[email protected]',
21
- 'kiran jadhav': '[email protected]',
22
- 'Bhavin Parmar': '[email protected]',
23
- 'RJ': '[email protected]',
24
- 'VS': '[email protected]',
25
- 'Roshani Mohan': '[email protected]',
26
- 'omkarsp': '[email protected]',
27
- 'Abhilash Sawant': '[email protected]',
28
- 'Hemant Yadav': '[email protected]',
29
- 'SandeeP Salunkhe': '[email protected]',
30
- 'Abhimanyu':'[email protected]',
31
- 'Sid': '[email protected]',
32
- 'chetanpatole': '[email protected]',
33
- 'Shweta Kanungo': '[email protected]',
34
- 'chandnichaurasia': '[email protected]',
35
- 'Rasika': '[email protected]',
36
- 'Bhushan Khapare': '[email protected]',
37
- 'daily-alerts-for-unsubscribed-companies': 'daily-alerts-for-unsu-aaaanufptnpzgjtmknapgi45oq@gofynd.slack.com',
38
- 'finance_team_internal': 'finance_team_internal-aaaabrz6gd5km3hjwxs7saxa4a@gofynd.slack.com',
39
- 'valyx-fynd-poc': '[email protected]',
40
- 'valyx_auto_invoices': '[email protected]'
41
- }
42
-
43
- gmail_addresses = {
44
- 'ninadmandavkar': '[email protected]',
45
- 'omkarsp': '[email protected]',
46
- 'Priyanshi Nahata': '[email protected]',
47
- 'kiran jadhav': '[email protected]',
48
- 'Bhavin Parmar': '[email protected]',
49
- 'RJ': '[email protected]',
50
- 'VS': '[email protected]',
51
- 'Roshani Mohan': '[email protected]',
52
- 'Abhilash Sawant': '[email protected]',
53
- 'Hemant Yadav': '[email protected]',
54
- 'SandeeP Salunkhe': '[email protected]',
55
- 'Abhimanyu':'[email protected]',
56
- 'Sid': '[email protected]',
57
- 'chetanpatole': '[email protected]',
58
- 'Shweta Kanungo': '[email protected]',
59
- 'chandnichaurasia': '[email protected]',
60
- 'Rasika': '[email protected]',
61
- 'Bhushan Khapare': '[email protected]',
62
- 'daily-alerts-for-unsubscribed-companies': 'daily-alerts-for-unsu-aaaanufptnpzgjtmknapgi45oq@gofynd.slack.com',
63
- 'finance_team_internal': 'finance_team_internal-aaaabrz6gd5km3hjwxs7saxa4a@gofynd.slack.com',
64
- 'valyx-fynd-poc': '[email protected]',
65
- 'valyx_auto_invoices': '[email protected]'
66
-
67
- }
68
-
69
- Webhook_urls = {
70
- 'ninadmandavkar': 'https://hooks.slack.com/services/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',
71
- 'Priyanshi Nahata': 'https://hooks.slack.com/services/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',
72
- 'kiran jadhav': 'https://hooks.slack.com/services/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',
73
- 'Bhavin Parmar': 'https://hooks.slack.com/services/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',
74
- 'RJ': 'https://hooks.slack.com/services/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',
75
- 'VS': 'https://hooks.slack.com/services/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',
76
- 'Roshani Mohan': 'https://hooks.slack.com/services/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',
77
- 'omkarsp': 'https://hooks.slack.com/services/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',
78
- 'Abhilash Sawant': 'https://hooks.slack.com/services/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',
79
- 'Hemant Yadav': 'https://hooks.slack.com/services/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',
80
- 'SandeeP Salunkhe': 'https://hooks.slack.com/services/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',
81
- 'Abhimanyu':'https://hooks.slack.com/services/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',
82
- 'Sid': 'https://hooks.slack.com/services/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',
83
- 'chetanpatole': 'https://hooks.slack.com/services/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',
84
- 'Shweta Kanungo': 'https://hooks.slack.com/services/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',
85
- 'chandnichaurasia': 'https://hooks.slack.com/services/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',
86
- 'Rasika': 'https://hooks.slack.com/services/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',
87
- 'Bhushan Khapare': 'https://hooks.slack.com/services/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',
88
- 'daily-alerts-for-unsubscribed-companies': 'https://hooks.slack.com/services/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',
89
- 'finance_team_internal': 'https://hooks.slack.com/services/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',
90
- 'valyx-fynd-poc': 'https://hooks.slack.com/services/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',
91
- 'valyx_auto_invoices': 'https://hooks.slack.com/services/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'
92
- }
93
 
94
  # Define your email server details
95
  EMAIL_HOST = 'smtp.gmail.com'
@@ -97,268 +13,40 @@ EMAIL_PORT = 587
97
  EMAIL_HOST_USER = '[email protected]'
98
  EMAIL_HOST_PASSWORD = 'vxay jiss cctw lsdo'
99
 
100
- def send_message_via_email(message, email_address, files, subject=None, body=None):
101
- try:
102
- # Set up the server
103
- server = smtplib.SMTP(EMAIL_HOST, EMAIL_PORT)
104
- server.starttls()
105
- server.login(EMAIL_HOST_USER, EMAIL_HOST_PASSWORD)
106
-
107
- # Create the email
108
- msg = MIMEMultipart()
109
- msg['From'] = EMAIL_HOST_USER
110
- msg['To'] = email_address
111
- msg['Subject'] = subject if subject else "🚨 Alerter"
112
-
113
- # Attach the message body
114
- msg.attach(MIMEText(body if body else message, 'plain'))
115
-
116
- # Attach each file if provided
117
- if files:
118
- for uploaded_file in files:
119
- part = MIMEBase('application', 'octet-stream')
120
- part.set_payload(uploaded_file.read())
121
- encoders.encode_base64(part)
122
- part.add_header('Content-Disposition', f'attachment; filename={uploaded_file.name}')
123
- msg.attach(part)
124
-
125
- # Send the email
126
- server.sendmail(EMAIL_HOST_USER, email_address, msg.as_string())
127
- server.quit()
128
- return True, "Message sent successfully"
129
- except Exception as e:
130
- return False, str(e)
131
-
132
- def send_message_via_webhook(message, webhook_url):
133
- try:
134
- payload = {
135
- "text": message
136
- }
137
- response = requests.post(webhook_url, json=payload)
138
- response.raise_for_status()
139
- return True, "Message sent successfully"
140
- except requests.exceptions.RequestException as e:
141
- return False, str(e)
142
-
143
- def main():
144
-
145
- # Path to your image
146
- image_path = "Designer (1).png"
147
- base64_image = get_base64_image(image_path)
148
-
149
- # # Define the CSS for setting the background image
150
- # background_image_css = f"""
151
- # <style>
152
- # .stApp {{
153
- # background-image: url(data:image/png;base64,{base64_image});
154
- # background-size: cover;
155
- # background-repeat: no-repeat;
156
- # background-attachment: fixed;
157
- # background-position: center;
158
- # height: 700vh; /* Make sure the background covers the full viewport height */
159
-
160
- # }}
161
- # </style>
162
- # """
163
-
164
- # # Apply the CSS to the Streamlit app
165
- # st.markdown(background_image_css, unsafe_allow_html=True)
166
 
167
-
168
-
169
- html_title = """
170
- <style>
171
- .fixed-title {
172
- font-size: 60px;
173
- color: #ffffff;
174
- background-image: linear-gradient(to right, #ff0000, #ffdab9);
175
- background-clip: text;
176
- -webkit-background-clip: text;
177
- text-fill-color: transparent;
178
- -webkit-text-fill-color: transparent;
179
- text-shadow: 2px 2px 4px rgba(0,0,0,0.4);
180
- }
181
- </style>
182
- <h1 class="fixed-title">Alerter</h1>
183
- """
184
- st.markdown(html_title, unsafe_allow_html=True)
185
-
186
- st.write("")
187
- st.write("")
188
- st.write("")
189
-
190
- html_subject = """
191
- <html>
192
- <head>
193
  <style>
194
- .button {
195
- display: inline-block;
196
- padding: 10px 20px;
197
- border-radius: 12px;
198
- background: linear-gradient(to bottom, #f8f9fa, #e0e0e0);
199
- box-shadow:
200
- 0 6px 12px rgba(0, 0, 0, 0.3),
201
- 0 8px 16px rgba(0, 0, 0, 0.2),
202
- inset 0 -2px 4px rgba(255, 255, 255, 0.6);
203
- text-align: center;
204
- position: relative;
205
- transform: translateY(4px);
206
- transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
207
- cursor: pointer;
208
- user-select: none;
209
- }
210
- .button:hover {
211
- box-shadow:
212
- 0 8px 16px rgba(0, 0, 0, 0.3),
213
- 0 12px 24px rgba(0, 0, 0, 0.2);
214
- transform: translateY(2px);
215
- }
216
- .button:active {
217
- box-shadow:
218
- 0 4px 8px rgba(0, 0, 0, 0.3),
219
- 0 6px 12px rgba(0, 0, 0, 0.2);
220
- transform: translateY(0);
221
  }
222
  </style>
223
- </head>
224
- <body>
225
- <div class="button">
226
- <h3 style="
227
- font-size: 20px;
228
- color: #ffffff;
229
- background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9);
230
- background-clip: text;
231
- -webkit-background-clip: text;
232
- text-fill-color: transparent;
233
- -webkit-text-fill-color: transparent;
234
- margin: 0;
235
- text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
236
- ">Write a Slack message</h3>
237
- </div>
238
- </body>
239
- </html>
240
  """
 
241
 
 
 
 
 
242
 
 
 
 
 
 
 
 
 
 
243
 
244
- st.markdown(html_subject, unsafe_allow_html=True)
245
- message = st.text_area("", "")
246
-
247
-
248
- # File uploader widget with a unique key
249
- html_subject = """
250
- <html>
251
- <head>
252
- <style>
253
- .button {
254
- display: inline-block;
255
- padding: 10px 20px;
256
- border-radius: 12px;
257
- background: linear-gradient(to bottom, #f8f9fa, #e0e0e0);
258
- box-shadow:
259
- 0 6px 12px rgba(0, 0, 0, 0.3),
260
- 0 8px 16px rgba(0, 0, 0, 0.2),
261
- inset 0 -2px 4px rgba(255, 255, 255, 0.6);
262
- text-align: center;
263
- position: relative;
264
- transform: translateY(4px);
265
- transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
266
- cursor: pointer;
267
- user-select: none;
268
- }
269
- .button:hover {
270
- box-shadow:
271
- 0 8px 16px rgba(0, 0, 0, 0.3),
272
- 0 12px 24px rgba(0, 0, 0, 0.2);
273
- transform: translateY(2px);
274
- }
275
- .button:active {
276
- box-shadow:
277
- 0 4px 8px rgba(0, 0, 0, 0.3),
278
- 0 6px 12px rgba(0, 0, 0, 0.2);
279
- transform: translateY(0);
280
- }
281
- </style>
282
- </head>
283
- <body>
284
- <div class="button">
285
- <h3 style="
286
- font-size: 20px;
287
- color: #ffffff;
288
- background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9);
289
- background-clip: text;
290
- -webkit-background-clip: text;
291
- text-fill-color: transparent;
292
- -webkit-text-fill-color: transparent;
293
- margin: 0;
294
- text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
295
- ">Upload documents</h3>
296
- </div>
297
- </body>
298
- </html>
299
- """
300
-
301
-
302
- st.markdown(html_subject, unsafe_allow_html=True)
303
- uploaded_file = st.file_uploader("", type=["pdf", "docx", "png", "jpeg", "xlsx", "csv", "json"], key="file_uploader", accept_multiple_files= True)
304
-
305
- # Dropdown for channels/members
306
- options = list(Slack_email_addresses.keys())
307
- html_subject = """
308
- <html>
309
- <head>
310
- <style>
311
- .button {
312
- display: inline-block;
313
- padding: 10px 20px;
314
- border-radius: 12px;
315
- background: linear-gradient(to bottom, #f8f9fa, #e0e0e0);
316
- box-shadow:
317
- 0 6px 12px rgba(0, 0, 0, 0.3),
318
- 0 8px 16px rgba(0, 0, 0, 0.2),
319
- inset 0 -2px 4px rgba(255, 255, 255, 0.6);
320
- text-align: center;
321
- position: relative;
322
- transform: translateY(4px);
323
- transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
324
- cursor: pointer;
325
- user-select: none;
326
- }
327
- .button:hover {
328
- box-shadow:
329
- 0 8px 16px rgba(0, 0, 0, 0.3),
330
- 0 12px 24px rgba(0, 0, 0, 0.2);
331
- transform: translateY(2px);
332
- }
333
- .button:active {
334
- box-shadow:
335
- 0 4px 8px rgba(0, 0, 0, 0.3),
336
- 0 6px 12px rgba(0, 0, 0, 0.2);
337
- transform: translateY(0);
338
- }
339
- </style>
340
- </head>
341
- <body>
342
- <div class="button">
343
- <h3 style="
344
- font-size: 20px;
345
- color: #ffffff;
346
- background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9);
347
- background-clip: text;
348
- -webkit-background-clip: text;
349
- text-fill-color: transparent;
350
- -webkit-text-fill-color: transparent;
351
- margin: 0;
352
- text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
353
- ">Select channels/members</h3>
354
- </div>
355
- </body>
356
- </html>
357
- """
358
-
359
-
360
- st.markdown(html_subject, unsafe_allow_html=True)
361
- selection = st.multiselect("", options)
362
 
363
  html_subject = """
364
  <html>
@@ -406,16 +94,16 @@ def main():
406
  -webkit-text-fill-color: transparent;
407
  margin: 0;
408
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
409
- ">Enter the subject(optional)</h3>
410
  </div>
411
  </body>
412
  </html>
413
  """
414
 
415
-
416
  st.markdown(html_subject, unsafe_allow_html=True)
417
- subject = st.text_input("", "",key ="subject_text_input")
418
 
 
 
419
 
420
 
421
  html_subject = """
@@ -464,18 +152,47 @@ def main():
464
  -webkit-text-fill-color: transparent;
465
  margin: 0;
466
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
467
- ">Enter the body (optional)</h3>
468
  </div>
469
  </body>
470
  </html>
471
  """
472
 
473
-
474
  st.markdown(html_subject, unsafe_allow_html=True)
475
- body = st.text_area("", "", key="body_text_area")
476
-
477
-
478
- button_styles = """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
479
  <style>
480
  div.stButton > button {
481
  color: #ffffff; /* Text color */
@@ -496,63 +213,43 @@ def main():
496
  }
497
  </style>
498
  """
499
- st.markdown(button_styles, unsafe_allow_html=True)
500
-
501
- col1, col2 = st.columns([0.125, 0.5])
502
- with col1:
503
- if st.button("Send to Slack"):
504
- if not message and not uploaded_file:
505
- st.error("Please enter a message or upload a document before sending.")
506
- return
507
-
508
- if not selection:
509
- st.error("Please select at least one channel or member")
510
- return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
511
 
512
- for item in selection:
513
- if uploaded_file:
514
- # Send the document via email
515
- email_address = Slack_email_addresses.get(item)
516
- if email_address:
517
- success, response_message = send_message_via_email(message, email_address, uploaded_file, subject, body)
518
- # if success:
519
- # st.success(f"Document sent to {item} via email.")
520
- # else:
521
- # st.error(f"Failed to send document to {item}: {response_message}")
522
- else:
523
- st.error(f"No email address found for {item}.")
524
- elif message:
525
- # Send the message via Slack webhook
526
- webhook_url = Webhook_urls.get(item)
527
- if webhook_url:
528
- success, response_message = send_message_via_webhook(message, webhook_url)
529
- # if success:
530
- # st.success(f"Message sent to {item} via Slack webhook.")
531
- # else:
532
- # st.error(f"Failed to send message to {item}: {response_message}")
533
- else:
534
- st.error(f"No webhook URL found for {item}.")
535
-
536
- with col2:
537
- if st.button("Send to Gmail"):
538
- if not message and not uploaded_file:
539
- st.error("Please enter a message or upload a document before sending.")
540
- return
541
-
542
- if not selection:
543
- st.error("Please select at least one channel or member")
544
- return
545
-
546
- for item in selection:
547
- email_address = gmail_addresses.get(item)
548
- if email_address:
549
- success, response_message = send_message_via_email(message, email_address, uploaded_file, subject, body)
550
- # if success:
551
- # st.success(f"Message sent to {item} via Gmail.")
552
- # else:
553
- # st.error(f"Failed to send message to {item}: {response_message}")
554
- else:
555
- st.error(f"No Gmail address found for {item}.")
556
 
557
- if __name__ == "__main__":
558
- main()
 
 
1
  import streamlit as st
2
+ import pandas as pd
3
  import smtplib
 
4
  from email.mime.text import MIMEText
5
+ from email.mime.multipart import MIMEMultipart
6
+ import gspread
7
+ from oauth2client.service_account import ServiceAccountCredentials
8
+ from streamlit_option_menu import option_menu
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  # Define your email server details
11
  EMAIL_HOST = 'smtp.gmail.com'
 
13
  EMAIL_HOST_USER = '[email protected]'
14
  EMAIL_HOST_PASSWORD = 'vxay jiss cctw lsdo'
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
+ html_title = """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  <style>
19
+ .fixed-title {
20
+ font-size: 60px;
21
+ color: #ffffff;
22
+ background-image: linear-gradient(to right, #ff0000, #ffdab9);
23
+ background-clip: text;
24
+ -webkit-background-clip: text;
25
+ text-fill-color: transparent;
26
+ -webkit-text-fill-color: transparent;
27
+ text-shadow: 2px 2px 4px rgba(0,0,0,0.4);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  }
29
  </style>
30
+ <h1 class="fixed-title">Alerter</h1>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  """
32
+ st.markdown(html_title, unsafe_allow_html=True)
33
 
34
+ menu_options = [
35
+ {"label": "Internal users", "icon": "📄", "description": "Upload a document and schedule it for email"},
36
+ {"label": "External users", "icon": "📊", "description": "Schedule an email with BigQuery data"}
37
+ ]
38
 
39
+ # Create the custom option menu
40
+ selected_option = option_menu(
41
+ menu_title="Select Integration", # Title of the menu
42
+ options=[option["label"] for option in menu_options], # Displayed options
43
+ icons=[option["icon"] for option in menu_options], # Icons next to options
44
+ menu_icon="cast", # Icon for the entire menu
45
+ default_index=0, # Default selected option
46
+ orientation="horizontal" # Orientation of the menu (can be vertical or horizontal)
47
+ )
48
 
49
+ if selected_option == "External users":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
  html_subject = """
52
  <html>
 
94
  -webkit-text-fill-color: transparent;
95
  margin: 0;
96
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
97
+ ">Select an option</h3>
98
  </div>
99
  </body>
100
  </html>
101
  """
102
 
 
103
  st.markdown(html_subject, unsafe_allow_html=True)
 
104
 
105
+
106
+ upload_option = st.radio("", ["Upload Spreadsheet (CSV or Excel)", "Google Sheets URL"])
107
 
108
 
109
  html_subject = """
 
152
  -webkit-text-fill-color: transparent;
153
  margin: 0;
154
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
155
+ ">Upload documents</h3>
156
  </div>
157
  </body>
158
  </html>
159
  """
160
 
 
161
  st.markdown(html_subject, unsafe_allow_html=True)
162
+ if upload_option == "Upload Spreadsheet (CSV or Excel)":
163
+ uploaded_file = st.file_uploader("", type=["csv", "xlsx"])
164
+ if uploaded_file:
165
+ # Load the data
166
+ if uploaded_file.name.endswith(".csv"):
167
+ df = pd.read_csv(uploaded_file)
168
+ else:
169
+ df = pd.read_excel(uploaded_file)
170
+
171
+ elif upload_option == "Google Sheets URL":
172
+ sheet_url = st.text_input("Enter Google Sheets URL")
173
+ if sheet_url:
174
+ try:
175
+ # Define the scope
176
+ scope = ["https://spreadsheets.google.com/feeds", 'https://www.googleapis.com/auth/drive']
177
+
178
+ # Add credentials
179
+ creds = ServiceAccountCredentials.from_json_keyfile_name('fynd-db-48954327ef17.json', scope)
180
+ client = gspread.authorize(creds)
181
+
182
+ # Get the sheet data
183
+ sheet = client.open_by_url(sheet_url).sheet1
184
+ data = sheet.get_all_records()
185
+ df = pd.DataFrame(data)
186
+
187
+ except Exception as e:
188
+ st.error(f"Failed to load Google Sheets: {str(e)}")
189
+
190
+ if 'df' in locals():
191
+ # Display the data (excluding the 'status' column)
192
+ df = df.drop(columns=['status'], errors='ignore')
193
+ st.dataframe(df)
194
+
195
+ button_styles = """
196
  <style>
197
  div.stButton > button {
198
  color: #ffffff; /* Text color */
 
213
  }
214
  </style>
215
  """
216
+ st.markdown(button_styles, unsafe_allow_html=True)
217
+
218
+ if st.button("Send Emails"):
219
+ # Send emails
220
+ for index, row in df.iterrows():
221
+ email = row['Email Addresses']
222
+ subject = row['Subject']
223
+ message = row['Message']
224
+ cc_addresses = row['CC Addresses'].split(',') if 'CC Addresses' in row else []
225
+ Folder_IDs = row['Folder IDs']
226
+ # company_name = row['Company_Name']
227
+ # company_id = row['Company_ID']
228
+
229
+ # Create the email
230
+ msg = MIMEMultipart()
231
+ msg['From'] = EMAIL_HOST_USER
232
+ msg['To'] = email
233
+ msg['Subject'] = subject
234
+
235
+ if cc_addresses:
236
+ msg['Cc'] = ','.join(cc_addresses)
237
+
238
+ body = f"\n\n{Folder_IDs}"
239
+ msg.attach(MIMEText(body, 'plain'))
240
+
241
+ try:
242
+ # Send the email
243
+ with smtplib.SMTP(EMAIL_HOST, EMAIL_PORT) as server:
244
+ server.starttls()
245
+ server.login(EMAIL_HOST_USER, EMAIL_HOST_PASSWORD)
246
+ server.send_message(msg)
247
+ st.success(f"Email sent to {email}")
248
+ except Exception as e:
249
+ st.error(f"Failed to send email to {email}: {str(e)}")
250
 
251
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
 
253
+ elif selected_option == "Internal users":
254
+ with open('ap.py') as file:
255
+ exec(file.read())