Ninad077 commited on
Commit
f74bbcc
·
verified ·
1 Parent(s): 6650167

Upload 4 files

Browse files
Files changed (2) hide show
  1. ap.py +48 -45
  2. app.py +74 -5
ap.py CHANGED
@@ -6,6 +6,9 @@ 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):
@@ -17,23 +20,23 @@ def get_base64_image(image_path):
17
  # Define your Slack email addresses and webhook URLs
18
  Slack_email_addresses = {
19
  'Rahul Mandowara': '[email protected]',
20
- 'Abhimanyu':'[email protected]',
21
- 'VS': '[email protected]',
22
- 'ninadmandavkar': '[email protected]',
23
  'Priyanshi Nahata': '[email protected]',
24
- 'kiran jadhav': '[email protected]',
25
  'Bhavin Parmar': '[email protected]',
26
- 'RJ': '[email protected]',
27
  'Roshani Mohan': '[email protected]',
28
- 'omkarsp': '[email protected]',
29
  'Abhilash Sawant': '[email protected]',
30
  'Hemant Yadav': '[email protected]',
31
- 'SandeeP Salunkhe': '[email protected]',
32
- 'Sid': '[email protected]',
33
- 'chetanpatole': '[email protected]',
34
  'Shweta Kanungo': '[email protected]',
35
- 'chandnichaurasia': '[email protected]',
36
- 'Rasika': '[email protected]',
37
  'Bhushan Khapare': '[email protected]',
38
  'Vaibhavi':'[email protected]',
39
  'daily-alerts-for-unsubscribed-companies': 'daily-alerts-for-unsu-aaaanufptnpzgjtmknapgi45oq@gofynd.slack.com',
@@ -45,22 +48,22 @@ Slack_email_addresses = {
45
  gmail_addresses = {
46
  'Rahul Mandowara': '[email protected]',
47
  'Abhimanyu':'[email protected]',
48
- 'VS': '[email protected]',
49
- 'ninadmandavkar': '[email protected]',
50
- 'omkarsp': '[email protected]',
51
  'Priyanshi Nahata': '[email protected]',
52
- 'kiran jadhav': '[email protected]',
53
  'Bhavin Parmar': '[email protected]',
54
- 'RJ': '[email protected]',
55
  'Roshani Mohan': '[email protected]',
56
  'Abhilash Sawant': '[email protected]',
57
  'Hemant Yadav': '[email protected]',
58
- 'SandeeP Salunkhe': '[email protected]',
59
- 'Sid': '[email protected]',
60
- 'chetanpatole': '[email protected]',
61
  'Shweta Kanungo': '[email protected]',
62
- 'chandnichaurasia': '[email protected]',
63
- 'Rasika': '[email protected]',
64
  'Bhushan Khapare': '[email protected]',
65
  'Vaibhavi': '[email protected]',
66
  'daily-alerts-for-unsubscribed-companies': 'daily-alerts-for-unsu-aaaanufptnpzgjtmknapgi45oq@gofynd.slack.com',
@@ -71,30 +74,30 @@ gmail_addresses = {
71
  }
72
 
73
  Webhook_urls = {
74
- 'Rahul Mandowara': 'https://hooks.slack.com/services/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',
75
- 'Abhimanyu':'https://hooks.slack.com/services/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',
76
- 'VS': 'https://hooks.slack.com/services/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',
77
- 'ninadmandavkar': 'https://hooks.slack.com/services/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',
78
- 'Priyanshi Nahata': 'https://hooks.slack.com/services/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',
79
- 'kiran jadhav': 'https://hooks.slack.com/services/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',
80
- 'Bhavin Parmar': 'https://hooks.slack.com/services/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',
81
- 'RJ': 'https://hooks.slack.com/services/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',
82
- 'Roshani Mohan': 'https://hooks.slack.com/services/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',
83
- 'omkarsp': 'https://hooks.slack.com/services/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',
84
- 'Abhilash Sawant': 'https://hooks.slack.com/services/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',
85
- 'Hemant Yadav': 'https://hooks.slack.com/services/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',
86
- 'SandeeP Salunkhe': 'https://hooks.slack.com/services/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',
87
- 'Sid': 'https://hooks.slack.com/services/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',
88
- 'chetanpatole': 'https://hooks.slack.com/services/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',
89
- 'Shweta Kanungo': 'https://hooks.slack.com/services/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',
90
- 'chandnichaurasia': 'https://hooks.slack.com/services/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',
91
- 'Rasika': 'https://hooks.slack.com/services/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',
92
- 'Bhushan Khapare': 'https://hooks.slack.com/services/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',
93
- 'Vaibhavi': 'https://hooks.slack.com/services/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',
94
- 'daily-alerts-for-unsubscribed-companies': 'https://hooks.slack.com/services/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',
95
- 'finance_team_internal': 'https://hooks.slack.com/services/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',
96
- 'valyx-fynd-poc': 'https://hooks.slack.com/services/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',
97
- 'valyx_auto_invoices': 'https://hooks.slack.com/services/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'
98
  }
99
 
100
  # Define your email server details
 
6
  from email import encoders
7
  import requests
8
  import base64
9
+ import os
10
+
11
+
12
 
13
  # Encode the image to Base64
14
  def get_base64_image(image_path):
 
20
  # Define your Slack email addresses and webhook URLs
21
  Slack_email_addresses = {
22
  'Rahul Mandowara': '[email protected]',
23
+ 'Abhimanyu Malik':'[email protected]',
24
+ 'Viky Sangoi': '[email protected]',
25
+ 'Ninad Mandavkar': '[email protected]',
26
  'Priyanshi Nahata': '[email protected]',
27
+ 'Kiran Jadhav': '[email protected]',
28
  'Bhavin Parmar': '[email protected]',
29
+ 'Rasika Jadhav': '[email protected]',
30
  'Roshani Mohan': '[email protected]',
31
+ 'Omkar Pawar': '[email protected]',
32
  'Abhilash Sawant': '[email protected]',
33
  'Hemant Yadav': '[email protected]',
34
+ 'Sandeep Salunkhe': '[email protected]',
35
+ 'Siddhesh Mayekar': '[email protected]',
36
+ 'Chetan Patole': '[email protected]',
37
  'Shweta Kanungo': '[email protected]',
38
+ 'Chandni Chaurasia': '[email protected]',
39
+ 'Rasika Salunkhe': '[email protected]',
40
  'Bhushan Khapare': '[email protected]',
41
  'Vaibhavi':'[email protected]',
42
  'daily-alerts-for-unsubscribed-companies': 'daily-alerts-for-unsu-aaaanufptnpzgjtmknapgi45oq@gofynd.slack.com',
 
48
  gmail_addresses = {
49
  'Rahul Mandowara': '[email protected]',
50
  'Abhimanyu':'[email protected]',
51
+ 'Viky Sangoi': '[email protected]',
52
+ 'Ninad Mandavkar': '[email protected]',
53
+ 'Omkar Pawar': '[email protected]',
54
  'Priyanshi Nahata': '[email protected]',
55
+ 'Kiran Jadhav': '[email protected]',
56
  'Bhavin Parmar': '[email protected]',
57
+ 'Rasika Jadhav': '[email protected]',
58
  'Roshani Mohan': '[email protected]',
59
  'Abhilash Sawant': '[email protected]',
60
  'Hemant Yadav': '[email protected]',
61
+ 'Sandeeo Salunkhe': '[email protected]',
62
+ 'Siddhesh Mayekar': '[email protected]',
63
+ 'Chetan Patole': '[email protected]',
64
  'Shweta Kanungo': '[email protected]',
65
+ 'Chandni Chaurasia': '[email protected]',
66
+ 'Rasika Salunkhe': '[email protected]',
67
  'Bhushan Khapare': '[email protected]',
68
  'Vaibhavi': '[email protected]',
69
  'daily-alerts-for-unsubscribed-companies': 'daily-alerts-for-unsu-aaaanufptnpzgjtmknapgi45oq@gofynd.slack.com',
 
74
  }
75
 
76
  Webhook_urls = {
77
+ 'Rahul Mandowara': os.getenv('Slack_Rahul'),
78
+ 'Abhimanyu Malik': os.getenv('Slack_Abhimanyu'),
79
+ 'Viky Sangoi': os.getenv('VS'),
80
+ 'Ninad Mandavkar': os.getenv('SLACK_NINAD'),
81
+ 'Priyanshi Nahata': os.getenv('Slack_Priyanshi'),
82
+ 'Kiran Jadhav': os.getenv('Slack_Kiran'),
83
+ 'Bhavin Parmar': os.getenv('Slack_Bhavin'),
84
+ 'Rasika Jadhav': os.getenv('Slack_RJ'),
85
+ 'Roshani Mohan': os.getenv('Slack_Roshani'),
86
+ 'Omkar Pawar': os.getenv('Slack_omkar'),
87
+ 'Abhilash Sawant': os.getenv('Slack_Abhilash'),
88
+ 'Hemant Yadav': os.getenv('Slack_Hemant'),
89
+ 'Sandeep Salunkhe': os.getenv('Slack_Sandeep'),
90
+ 'Siddhesh Mayekar': os.getenv('Slack_Sid'),
91
+ 'Chetan Patole': os.getenv('Slack_Chetan'),
92
+ 'Shweta Kanungo': os.getenv('Slack_Shweta'),
93
+ 'Chandni Chaurasia': os.getenv('Slack_Chandni'),
94
+ 'Rasika Salunkhe': os.getenv('Slack_Rasika'),
95
+ 'Bhushan Khapare': os.getenv('Slack_Bhushan'),
96
+ 'Vaibhavi': os.getenv('Slack_Vaibhavi'),
97
+ 'daily-alerts-for-unsubscribed-companies': os.getenv('Slack_daily_alerts'),
98
+ 'finance_team_internal': os.getenv('Slack_finance'),
99
+ 'valyx-fynd-poc': os.getenv('valyx_poc'),
100
+ 'valyx_auto_invoices': os.getenv('slack_valyx_auto')
101
  }
102
 
103
  # Define your email server details
app.py CHANGED
@@ -6,6 +6,30 @@ 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'
@@ -279,7 +303,7 @@ if selected_option == "External users":
279
  subject = row['Subject']
280
  message = row['Message']
281
  cc_addresses = row['CC Addresses'].split(',') if 'CC Addresses' in row else []
282
- Folder_IDs = row['Folder IDs']
283
  # company_name = row['Company_Name']
284
  # company_id = row['Company_ID']
285
 
@@ -292,16 +316,61 @@ if selected_option == "External users":
292
  if cc_addresses:
293
  msg['Cc'] = ','.join(cc_addresses)
294
 
295
- body = f"\n\n{Folder_IDs}"
296
  msg.attach(MIMEText(body, 'plain'))
297
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
  try:
299
- # Send the email
300
  with smtplib.SMTP(EMAIL_HOST, EMAIL_PORT) as server:
301
  server.starttls()
302
  server.login(EMAIL_HOST_USER, EMAIL_HOST_PASSWORD)
303
- server.send_message(msg)
304
- st.success(f"Email sent to {email}")
305
  except Exception as e:
306
  st.error(f"Failed to send email to {email}: {str(e)}")
307
 
 
6
  import gspread
7
  from oauth2client.service_account import ServiceAccountCredentials
8
  from streamlit_option_menu import option_menu
9
+ from io import BytesIO
10
+ import requests
11
+ from email.mime.application import MIMEApplication
12
+ import os
13
+
14
+ # Function to read files from local path
15
+ def read_file(path):
16
+ try:
17
+ with open(path, 'rb') as file:
18
+ return file.read()
19
+ except Exception as e:
20
+ st.error(f"Failed to read file from {path}: {str(e)}")
21
+ return None
22
+
23
+ # Function to get file content type based on file extension
24
+ def get_content_type(file_path):
25
+ if file_path.lower().endswith('.pdf'):
26
+ return 'application/pdf'
27
+ elif file_path.lower().endswith('.csv'):
28
+ return 'text/csv'
29
+ elif file_path.lower().endswith('.xlsx'):
30
+ return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
31
+ else:
32
+ return 'application/octet-stream'
33
 
34
  # Define your email server details
35
  EMAIL_HOST = 'smtp.gmail.com'
 
303
  subject = row['Subject']
304
  message = row['Message']
305
  cc_addresses = row['CC Addresses'].split(',') if 'CC Addresses' in row else []
306
+ Folder_IDs = row['Folder IDs'].split(',')
307
  # company_name = row['Company_Name']
308
  # company_id = row['Company_ID']
309
 
 
316
  if cc_addresses:
317
  msg['Cc'] = ','.join(cc_addresses)
318
 
319
+ body = f"""{message}"""
320
  msg.attach(MIMEText(body, 'plain'))
321
 
322
+
323
+ # Read and attach PDFs
324
+ for folder_id in Folder_IDs:
325
+ pdf_path = folder_id.strip()
326
+ if pdf_path.endswith('.pdf'):
327
+ pdf_content = read_file(pdf_path)
328
+ if pdf_content:
329
+ part = MIMEApplication(pdf_content, Name=os.path.basename(pdf_path))
330
+ part['Content-Disposition'] = f'attachment; filename="{os.path.basename(pdf_path)}"'
331
+ msg.attach(part)
332
+
333
+
334
+ # Read and attach CSV files
335
+ for folder_id in Folder_IDs:
336
+ csv_path = folder_id.strip()
337
+ if csv_path.endswith('.csv'):
338
+ csv_content = read_file(csv_path)
339
+ if csv_content:
340
+ part = MIMEApplication(csv_content, Name=os.path.basename(csv_path))
341
+ part['Content-Disposition'] = f'attachment; filename="{os.path.basename(csv_path)}"'
342
+ msg.attach(part)
343
+
344
+ # Read and attach XLSX files
345
+ for folder_id in Folder_IDs:
346
+ xlsx_path = folder_id.strip()
347
+ if xlsx_path.endswith('.xlsx'):
348
+ xlsx_content = read_file(xlsx_path)
349
+ if xlsx_content:
350
+ part = MIMEApplication(xlsx_content, Name=os.path.basename(xlsx_path))
351
+ part['Content-Disposition'] = f'attachment; filename="{os.path.basename(xlsx_path)}"'
352
+ msg.attach(part)
353
+
354
+
355
+
356
+ # Read and attach ZIP files
357
+ for folder_id in Folder_IDs:
358
+ zip_path = folder_id.strip()
359
+ if zip_path.endswith('.zip'):
360
+ zip_content = read_file(zip_path)
361
+ if zip_content:
362
+ part = MIMEApplication(zip_content, Name=os.path.basename(zip_path))
363
+ part['Content-Disposition'] = f'attachment; filename="{os.path.basename(zip_path)}"'
364
+ msg.attach(part)
365
+
366
+
367
+ # Send the email
368
  try:
 
369
  with smtplib.SMTP(EMAIL_HOST, EMAIL_PORT) as server:
370
  server.starttls()
371
  server.login(EMAIL_HOST_USER, EMAIL_HOST_PASSWORD)
372
+ server.sendmail(msg['From'], [email] + cc_addresses, msg.as_string())
373
+ st.success(f"Email sent to {email}")
374
  except Exception as e:
375
  st.error(f"Failed to send email to {email}: {str(e)}")
376