Currently, i am processing the input file all together. i am expecting to process input file iniduvally and send email.
US_input1.csv
US_input2.csv
US_input3.csv
US_input4.csv
US_input5.csv
US_input6.csv
US_input7.csv
US_input8.csv
#writing the column name
seen = set()
with open('inputfile.txt') as filenames, open('colfile.txt', 'w') as mfile:
for filename in filenames:
csvFile = pandas.read_csv(filename.strip(), sep="|", nrows=1)
# displaying the contents of the CSV file
for col in csvFile.columns:
COL= col.upper()
if not search("", COL):
h = hash(col)
if h not in seen:
mfile.write(col.upper() + "\n")
seen.add(h)
mfile.close()
with open('colfile.txt', 'r') as file1:
# Read the lines from the first text file
lines5 = file1.readlines()
file1.close()
# Convert the lines from the first text file to a set
lines5_set = set(lines5)
# Open the second text file in read mode
with open('measlisttable.txt', 'r') as file2:
# Read the lines from the second text file
lines10 = file2.readlines()
file2.close()
# Convert the lines from the second text file to a set
lines10_set = set(lines10)
# Find the unique lines between the two text files
unique_lines = lines5_set.difference(lines10_set)
# Iterate over the unique lines and print them
with open('output.txt', 'w') as sfile:
for line6 in unique_lines:
sfile.write("%s" % line6)
sfile.close()
#send email to user
SERVER1 = "user@mail.com"
TO=["test@mail.com"]
CC=["test@mail.com"]
FROM="test@mail.com"
SUBJECT = "extra field"
TEXT=""
TEXT0=""
email_file='output.txt'
fp = open(email_file,"r")
TEXT_LIST = fp.readlines()
fp.close()
email_file1='input.txt'
fp1 = open(email_file1,"r")
TEXT_LIST1 = fp1.readlines()
fp1.close()
for line in TEXT_LIST1:
TEXT0=TEXT0+"\n"+line
for line in TEXT_LIST:
TEXT=TEXT+"\n"+line
footer_msg=" "
header0= """
Processed Files:
"""
header= """
Below list to be added:
"""
footer = """
"""
TEXT = header0 + TEXT0 + header + TEXT + footer + footer_msg
# Prepare actual message
message = """\
From: %s
To: %s
Cc: %s
Subject: %s
%s
""" % (FROM, ", ".join(TO),", ".join(CC), SUBJECT, TEXT)
print(message)
# Send the mail
'''
server = smtplib.SMTP(SERVER1)
server.sendmail(FROM, TO, message)
server.set_debuglevel(2)
server.quit()
'''
try:
smtpObj = smtplib.SMTP(SERVER1)
smtpObj.sendmail(FROM, TO, message)
smtpObj.set_debuglevel(2)
print("Successfully sent email")
except:
print("Error: unable to send email")