Commit 7c93cb06 by mohammed.shibili

updated body content and cofiguration file

parent f63ae275
[server_details]
server_name=smtp.gmail.com
port_number=465
file_path=scripts/utils/Task3.xlsx
file_extension=xlsx
\ No newline at end of file
import configparser
# calling contents config files into a variable
config = configparser.ConfigParser()
config.read("configuration/application.conf")
file_root = config.get('server_details', 'file_path')
port_num = config.get('server_details', 'port_number')
server_nm = config.get('server_details', 'server_name')
file_ext = config.get('server_details', 'file_extension')
server_name = 'smtp.gmail.com'
port_number = '465'
import pandas as pd import pandas as pd
from scripts.config.server_details import file_root
# fetching body contents # fetching body contents
def body_content(): def body_content():
data_set = pd.read_excel("scripts/utils/Task3.xlsx") try:
data_set = pd.read_excel(file_root)
except Exception as e:
print(e, "error reading file")
column_mean = {} column_mean = {}
column_maximum = {} column_maximum = {}
column_minimum = {} column_minimum = {}
...@@ -13,10 +18,10 @@ def body_content(): ...@@ -13,10 +18,10 @@ def body_content():
continue continue
else: else:
timestamp = data_set['Timestamp'][data_set[cols].idxmax()] timestamp = data_set['Timestamp'][data_set[cols].idxmax()]
max_value = data_set[cols][data_set[cols].idxmax()] max_value = round(data_set[cols][data_set[cols].idxmax()], 2)
min_value = data_set[cols][data_set[cols].idxmin()] min_value = round(data_set[cols][data_set[cols].idxmin()], 2)
column_mean.update({cols: data_set[cols].mean()}) column_mean.update({cols: round(data_set[cols].mean(),2)})
column_maximum.update({timestamp: max_value}) column_maximum.update({timestamp: max_value})
column_minimum.update({timestamp: min_value}) column_minimum.update({timestamp: min_value})
body_message = f"average values {column_mean} \nmaximum value {column_maximum} \nminimum value {column_minimum}" body_message = f"average values {column_mean} \n\n\nmaximum value {column_maximum} \n\n\nminimum value {column_minimum}"
return body_message return body_message
from email.message import EmailMessage from email.message import EmailMessage
from scripts.config.server_details import file_root, file_ext
from scripts.core.handlers.content_for_body import body_content from scripts.core.handlers.content_for_body import body_content
...@@ -14,10 +15,9 @@ def file_attach(from_address, to_address, subject): ...@@ -14,10 +15,9 @@ def file_attach(from_address, to_address, subject):
msg['To'] = to_address1 msg['To'] = to_address1
msg['Subject'] = subject1 msg['Subject'] = subject1
msg.set_content(body) msg.set_content(body)
# opening file to be attached # opening file to be attached
with open("scripts/utils/Task3.xlsx", "rb") as file: with open(file_root, "rb") as file:
file_data = file.read() file_data = file.read()
file_name = file.name file_name = file.name
msg.add_attachment(file_data, maintype='application', subtype='xlsx', filename=file_name) msg.add_attachment(file_data, maintype='application', subtype=file_ext, filename=file_name)
return msg return msg
import smtplib import smtplib
from scripts.constants.server_details import server_name, port_number from scripts.config.server_details import port_num, server_nm
# mail authentication # mail authentication
def mail_access(from_address, email_password, message): def mail_access(from_address, email_password, message):
try: try:
with smtplib.SMTP_SSL(server_name, port_number) as smtp: with smtplib.SMTP_SSL(server_nm, port_num) as smtp:
smtp.login(from_address, email_password) smtp.login(from_address, email_password)
smtp.send_message(message) smtp.send_message(message)
except Exception as e: except Exception as e:
......
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