ayushkhare12

If Marketing files need to be send separtely, code Commented

Oct 8th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.43 KB | None | 0 0
  1. from send_email import send_mail
  2. import pandas as pd
  3. import os
  4. import re
  5.  
  6. email_detail_columns = ['filename', 'markets', 'email', 'email1', 'email2', 'email3']
  7. email_details = pd.read_csv('emails_and_files.csv', header=None, names=email_detail_columns, index_col='filename')
  8. report_details_columns = ['Reportname', 'rgm', 'mm', 'cm']
  9. reportname = pd.read_csv('details.csv', names=report_details_columns, index_col='Reportname')
  10.  
  11. for detail in email_details.index:
  12.     email_ids = []
  13.     files = []
  14.     if re.search(r'region', detail):
  15.         email_ids.append(email_details.loc[detail].email)
  16.         # print(email_details.loc[detail].email)
  17.         markets = email_details.loc[detail].markets.split(';')
  18.         # marketing_files = []
  19.         for report in reportname.index:
  20.             if reportname.loc[report].rgm == 't':
  21.                 path = os.path.join(report, 'pdf')
  22.                 for r, d, f in os.walk(path):
  23.                     for file in f:
  24.                         if file.replace(' report.csv', '') == detail or (file.replace(' report.csv', '') in markets):#This goes if file.replace(' report.csv', '') == detail
  25.                             files.append(os.path.join(path, file))
  26.                         # elif file.replace(' report.csv', '') in markets:
  27.                         #     marketing_files.append(os.path.join(path, file))
  28.                        
  29.                        
  30.         if files:
  31.             send_mail("[email protected]", '{0} rgm reports'.format(detail), 'PFA', email_ids,
  32.                       files=files)
  33.         # if marketing_files:
  34.         #     send_mail("[email protected]", '{0} rgm associated Marketing reports'.format(detail), 'PFA', email_ids,
  35.         #               files=marketing_files)
  36.            
  37.     elif detail.startswith('MKT'):
  38.         # email_ids.append(email_details.loc[detail].email)
  39.         # email_ids.append(email_details.loc[detail].email1)
  40.         # email_ids.append(email_details.loc[detail].email2)
  41.         email_ids = [email_details.loc[detail].email, email_details.loc[detail].email1, email_details.loc[detail].email2]
  42.  
  43.         if type(email_details.loc[detail].email3) == str:
  44.             email_ids.append(email_details.loc[detail].email3)
  45.         for report in reportname.index:
  46.             if reportname.loc[report].mm == 't':
  47.                 path = os.path.join(report, 'pdf')
  48.                 for r, d, f in os.walk(path):
  49.                     files_without_extension = [file.replace(' report.csv', '') for file in f]
  50.                     if detail in files_without_extension:
  51.                         files.append(os.path.join(path, detail + ' report.csv'))
  52.                 send_mail("[email protected]", '{0} mm reports'.format(detail), 'PFA', email_ids,
  53.                           files=files)
  54.     elif re.match(r'^\d\d\d\d', detail):
  55.         email_ids.append(email_details.loc[detail].email)
  56.         for report in reportname.index:
  57.             if reportname.loc[report].cm == 't':
  58.                 path = os.path.join(report, 'pdf')
  59.                 for r, d, f in os.walk(path):
  60.                     files_without_extension = [file.replace(' report.csv', '') for file in f]
  61.                     if detail in files_without_extension:
  62.                         files.append(os.path.join(path, detail + ' report.csv'))
  63.         send_mail("[email protected]", '{0} cm reports'.format(detail), 'PFA', email_ids, files=files)
Add Comment
Please, Sign In to add comment