Commit 037f767a by arjun.b

Mail attachment

parents
# Default ignored files
/shelf/
/workspace.xml
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N801" />
</list>
</option>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<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" 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/task-3.iml" filepath="$PROJECT_DIR$/.idea/task-3.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$" />
<orderEntry type="jdk" jdkName="Python 3.9" jdkType="Python SDK" />
<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
from scripts.services.main import send_mail
subject = "Mail attachment"
send_mail("b.arjun2149@gmail.com", "lasimudvzajqrzez", subject)
\ No newline at end of file
host = "smtp.gmail.com"
port = 587
import pandas as pd
dic_max = {}
dict_min={}
dic_mean={}
excel_file = pd.read_excel("E:\\task-3\\scripts\\utils\\task 3.xlsx")
def max_min():
try:
for columns in excel_file.columns:
timestamp_max = excel_file["Timestamp"][excel_file[columns].idxmax()]
timestamp_min = excel_file["Timestamp"][excel_file[columns].idxmin()]
max_value = excel_file[columns][excel_file[columns].idxmax()]
min_value = excel_file[columns][excel_file[columns].idxmin()]
dic_max.update({timestamp_max: max_value})
dict_min.update({timestamp_min: min_value})
dic_mean.update({columns: excel_file[columns].mean()})
except Exception as e:
print(str(e))
return f'Average_of_columns expect_timestamp:{dic_mean},\nmaximum_value:{dic_max},\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
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email import encoders
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
def send_mail(user_name, passwd, subject):
try:
recipient = ["arjyou79@gmail.com", "ajil.intern.knowledgelens@gmail.com", "shibilimohammed456@gmail.com"]
mail = MIMEMultipart('alternative')
mail['Subject'] = subject
mail['From'] = user_name
mail["To"] = ",".join(recipient)
message = max_min()
mail.attach(MIMEText(message, "plain"))
file_name = "E:\\task-3\\scripts\\utils\\task 3.xlsx"
with open(file_name, "rb") as f:
attachment = MIMEApplication(f.read(), Name=basename(file_name))
attachment['Content-Disposition'] = 'attachment; filename="{}"'.format(basename(file_name))
encoders.encode_base64(attachment)
mail.attach(attachment)
server = smtplib.SMTP(host, port)
server.starttls()
server.login(user_name, passwd)
server.sendmail(user_name, recipient, mail.as_string())
server.close()
print("mail sent!!!!")
except Exception as e:
print(str(e))
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