-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchartsmail.py
121 lines (99 loc) · 3.45 KB
/
chartsmail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import plotly
import plotly.graph_objs as go
from datetime import datetime
import smtplib
import cufflinks as cf
import datetime
from datetime import time
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
import time
import os
username = os.getlogin()
current_date_and_time1 =datetime.datetime.now() - datetime.timedelta(days=1)#date yesterday 1
current_date_and_time=current_date_and_time1.strftime('%Y-%m-%d')#date yesterday 1
current_date_and_time_string = str(current_date_and_time)
#print('',current_date_and_time) to display console
file_name = current_date_and_time_string + ".csv"
while True:
I020 = [line.strip('\n').split(",") for line in open(file_name)][1:]
Time = [datetime.datetime.strptime(line[1], "%H:%M:%S") for line in I020]
temp = [float(line[3]) for line in I020]
humy = [float(line[2]) for line in I020]
Water = [float(line[4]) for line in I020]
ph = [float(line[5]) for line in I020]
random_x = Time
random_y0 = temp
random_y1 = humy
random_y2 = Water
random_y3 = ph
trace0 = go.Scatter(
x=random_x,
y=random_y0,
mode='lines',
name='Temp(°C)'
)
trace1 = go.Scatter(
x=random_x,
y=random_y1,
mode='lines',
name='Humidity(%)'
)
trace2 = go.Scatter(
x=random_x,
y=random_y2,
mode='lines',
name='WaterTemp(°C)'
)
trace3 = go.Scatter(
x=random_x,
y=random_y3,
mode='lines',
name='pH'
)
# Structure traces as datasets
data1 = [trace0]
data2 = [trace1]
data3 = [trace2]
data4 = [trace3]
# Build figures
fig1 = go.Figure(data=data1)
fig2 = go.Figure(data=data2)
fig3 = go.Figure(data=data3)
fig4 = go.Figure(data=data4)
figs = cf.subplots([fig1, fig2, fig3, fig4], shape=(2, 2))
figs['layout'].update(height=630, width=1350, title='Data For Aquaponics')
plotly.offline.plot(figs,
filename='C:/Users/'+username+'/Supervision-of-an-aquaponics-system-by-a-command/update.html', show_link=False)
try:
sender_address = 'farahbenlassoued1@gmail.com'
sender_pass = 'farahtaz2020'
receiver_address = 'fayzasalhif@gmail.com'
msg = MIMEMultipart()
msg['From'] = sender_address
msg['To'] = receiver_address
msg['Subject'] = "Rapport Of {} ".format(current_date_and_time)
body = "Good Morning Sir."
msg.attach(MIMEText(body, 'plain'))
# open the file to be sent
filename = "Update OF Courbes.html"
attachment = open("C:/Users/"+username+"/Supervision-of-an-aquaponics-system-by-a-command/update.html", "rb")
p = MIMEBase('application', 'octet-stream')
p.set_payload((attachment).read())
encoders.encode_base64(p)
p.add_header('Content-Disposition', "attachment; filename= %s" % filename)
msg.attach(p)
# Create SMTP session for sending the mail
session = smtplib.SMTP('smtp.gmail.com', 587) # use gmail with port
session.starttls() # enable security
session.login(sender_address, sender_pass) # login with mail_id and password
text = msg.as_string()
session.sendmail(sender_address, receiver_address, text)
session.quit()
print('Mail Sent')
except:
print("Smtp Have Problem")
time.sleep(3600)