Commit 722d45da authored by arun.uday's avatar arun.uday

migrate to gitlab-pm

parents
# Default ignored files
/shelf/
/workspace.xml
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (task3)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/task3.iml" filepath="$PROJECT_DIR$/.idea/task3.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
# Reading excel and performing operations
from scripts.services.send_mail import create_mail
print("Using python to send mail and add attachments")
# sender password xnoeryrnirtbecdg
sent_conf = create_mail()
if sent_conf:
print("Mail sent successfully")
else:
print("Mail not sent")
# host
[host]
server_host = smtp.gmail.com
# port
[port]
port = 465
# excel file path
[file_path]
excel_path = scripts/utils/task3.xlsx
file_name = task3.xlsx
import configparser
# using configparser for getting config variables from application.conf
config = configparser.ConfigParser()
config.read("conf/application.conf")
host_address = config.get("host", "server_host")
port_number = config.get("port", "port")
path_excel = config['file_path']['excel_path']
file_name = config.get("file_path", "file_name")
# reading excel file contents
import pandas as pd
from scripts.config.app_path_config import path_excel
from scripts.core.handlers.format_body_email import data_format
def email_content_excel():
data_task = pd.read_excel(path_excel)
column_mean = {}
max_column = {}
min_column = {}
for col in data_task.columns:
if col == 'Timestamp':
continue
else:
# timestamp of max values
timestamp_max = data_task['Timestamp'][data_task[col].idxmax()]
# timestamp of min values
timestamp_min = data_task['Timestamp'][data_task[col].idxmin()]
# max values of each columns
max_val = round(data_task[col][data_task[col].idxmax()], 2)
# min values of each columns
min_val = round(data_task[col][data_task[col].idxmin()], 2)
# appending mean, max, min in to dictionaries
column_mean.update({col: round(data_task[col].mean(), 2)})
max_column.update({col: [timestamp_max, max_val]})
min_column.update({col: [timestamp_min, min_val]})
return data_format(column_mean, max_column, min_column)
# formatting the body for better view
import pandas as pd
from scripts.core.handlers.frames_format import format_data_frames
def data_format(column_mean, max_col, min_col):
# using generators to split the dictionary values
mean_col = (col for col in column_mean.items())
max_cols = (col for col in max_col.items())
min_cols = (col for col in min_col.items())
# creating dataframes form generators
mean_frame = pd.DataFrame(mean_col, columns=['Column_Names', 'Mean'])
max_frame = pd.DataFrame(max_cols, columns=['Column_Names', 't_Max'])
min_frame = pd.DataFrame(min_cols, columns=['Column_Names', 't_Min'])
# splitting list in to separate columns
max_frame[['Timestamp', 'Max_Values']] = max_frame['t_Max'].apply(pd.Series)
max_frame = max_frame.drop(columns=['t_Max'], axis=1)
min_frame[['Timestamp', 'Min_Values']] = min_frame['t_Min'].apply(pd.Series)
min_frame = min_frame.drop(columns=['t_Min'], axis=1)
return format_data_frames(mean_frame, max_frame, min_frame)
# format dataframes
from tabulate import tabulate
def format_data_frames(mean_frame, max_frame, min_frame):
mean_frame = tabulate(mean_frame, headers=mean_frame.columns)
max_frame = tabulate(max_frame, headers=max_frame.columns)
min_frame = tabulate(min_frame, headers=min_frame.columns)
return f'Mean Values \n{mean_frame} \n\n Max values of each columns \n{max_frame}\n\n' \
f' Min values of each columns\n{min_frame}'
# reading excel file
import ssl
from email.message import EmailMessage
from scripts.config.app_path_config import path_excel, file_name
from scripts.core.handlers.excel_file_content import email_content_excel
def content_create(sender_name, receiver_email, subject):
mail = EmailMessage()
mail['From'] = sender_name
mail['To'] = receiver_email
mail['Subject'] = subject
email_content_excel()
body = email_content_excel()
mail.set_content(body)
context = ''
try:
with open(path_excel, "rb") as file:
file_data = file.read()
mail.add_attachment(file_data, maintype='application', subtype='xlsx', filename=file_name)
context = ssl.create_default_context()
except Exception as e:
print(e)
return mail, context
# connecting to smtp
import smtplib
from scripts.config.app_path_config import host_address, port_number
def mail_send(email_address, email_password, receiver_email, mail, context):
# connecting to server
try:
with smtplib.SMTP_SSL(host_address, port_number, context=context) as smtp:
smtp.login(email_address, email_password)
# sending the mail
smtp.sendmail(email_address, receiver_email, mail.as_string())
except Exception as e:
print(e)
return False
else:
return True
# reading user inputs
from scripts.core.handlers.mail_content import content_create
from scripts.core.handlers.mail_send_smtp import mail_send
# creating mails
def create_mail():
email_address = input("enter your email")
sender_name = input("Enter sender name")
email_password = input("Enter your password")
receiver_email = []
num_cc = int(input("Enter the number of receivers"))
while num_cc > 0:
receiver_email.append(input())
num_cc = num_cc - 1
subject = input("Enter your subject")
content_create(sender_name, receiver_email, subject)
mail, context = content_create(sender_name, receiver_email, subject)
# send emails using smtp
return mail_send(email_address, email_password, receiver_email, mail, context)
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