Commit a7cf06c3 by arjun.b

body format changed and application_config file added

parent 037f767a
from scripts.config.application_config import sender_mail, sender_passwd
from scripts.services.main import send_mail from scripts.services.main import send_mail
subject = "Mail attachment" subject = "Mail attachment"
send_mail("b.arjun2149@gmail.com", "lasimudvzajqrzez", subject) send_mail(sender_mail, sender_passwd, subject)
\ No newline at end of file
file_name = "E:\\task-3\\scripts\\utils\\task 3.xlsx"
recipients = ["arjyou79@gmail.com", "ajil.intern.knowledgelens@gmail.com",
"shibilimohammed456@gmail.com", ]
sender_mail = "b.arjun2149@gmail.com"
sender_passwd = "lasimudvzajqrzez"
import pandas as pd import pandas as pd
dic_max = {} from scripts.config.application_config import file_name
dict_min={}
dic_mean={}
excel_file = pd.read_excel("E:\\task-3\\scripts\\utils\\task 3.xlsx")
def max_min(): def max_min():
dic_max = {}
dict_min = {}
dic_mean = {}
try: try:
excel_file = pd.read_excel(file_name)
for columns in excel_file.columns: for columns in excel_file.columns:
timestamp_max = excel_file["Timestamp"][excel_file[columns].idxmax()] if columns == "Timestamp":
timestamp_min = excel_file["Timestamp"][excel_file[columns].idxmin()] continue
max_value = excel_file[columns][excel_file[columns].idxmax()] else:
min_value = excel_file[columns][excel_file[columns].idxmin()] timestamp_max = excel_file["Timestamp"][excel_file[columns].idxmax()]
dic_max.update({timestamp_max: max_value}) timestamp_min = excel_file["Timestamp"][excel_file[columns].idxmin()]
dict_min.update({timestamp_min: min_value}) max_value = excel_file[columns][excel_file[columns].idxmax()]
dic_mean.update({columns: excel_file[columns].mean()}) min_value = excel_file[columns][excel_file[columns].idxmin()]
dic_max.update({columns: [timestamp_max, max_value]})
dict_min.update({columns: [timestamp_min, min_value]})
dic_mean.update({columns: round(excel_file[columns].mean(), 2)})
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
return f'Average_of_columns expect_timestamp:{dic_mean},\nmaximum_value:{dic_max},\nminimum_value:{dict_min}' return f'Average_of_columns expect_timestamp:{dic_mean},\n\n\nmaximum_value:{dic_max},\n\nminimum_value:{dict_min}'
import pandas as pd
excel_file = pd.read_excel("E:\\task-3\\scripts\\utils\\task 3.xlsx")
def module():
try:
for columns in excel_file.columns:
if columns == "Timestamp":
continue
else:
return {"kWh": excel_file['kWh'].mean(), "kVAh": excel_file["kVAh"].mean(),
"kW": excel_file["kW"].mean(), "kVA": excel_file["kVA"].mean(),
"current": excel_file["current"].mean(),
}
except Exception as e:
print(str(e))
import json
import sys
from os.path import basename
import pandas as pd
import smtplib import smtplib
from email import encoders
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText from email.mime.text import MIMEText
from email.mime.application import MIMEApplication from os.path import basename
from email import encoders
from scripts.config import application_config
from scripts.constants.server import host, port from scripts.constants.server import host, port
from scripts.core.handlers import body_one
from scripts.core.handlers.body_one import module
from scripts.core.handlers.body import max_min from scripts.core.handlers.body import max_min
def send_mail(user_name, passwd, subject): def send_mail(user_name, passwd, subject):
try: try:
recipient = ["arjyou79@gmail.com", "ajil.intern.knowledgelens@gmail.com", "shibilimohammed456@gmail.com"] recipient = application_config.recipients
mail = MIMEMultipart('alternative') mail = MIMEMultipart('alternative')
mail['Subject'] = subject mail['Subject'] = subject
mail['From'] = user_name mail['From'] = user_name
mail["To"] = ",".join(recipient) mail["To"] = ",".join(recipient)
message = max_min() message = max_min()
mail.attach(MIMEText(message, "plain")) mail.attach(MIMEText(message, "plain"))
file_name = application_config.file_name
file_name = "E:\\task-3\\scripts\\utils\\task 3.xlsx"
with open(file_name, "rb") as f: with open(file_name, "rb") as f:
attachment = MIMEApplication(f.read(), Name=basename(file_name)) attachment = MIMEApplication(f.read(), Name=basename(file_name))
attachment['Content-Disposition'] = 'attachment; filename="{}"'.format(basename(file_name)) attachment['Content-Disposition'] = 'attachment; filename="{}"'.format(basename(file_name))
...@@ -43,6 +36,3 @@ def send_mail(user_name, passwd, subject): ...@@ -43,6 +36,3 @@ def send_mail(user_name, passwd, subject):
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
print("mail not sent") print("mail not sent")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment