-
Notifications
You must be signed in to change notification settings - Fork 0
/
MailAlerts
54 lines (42 loc) · 1.35 KB
/
MailAlerts
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
import subprocess
import smtplib
import socket
from email.mime.text import MIMEText
import datetime
from time import sleep
from sense_hat import SenseHat
sense = SenseHat()
sense.clear()
pressure = sense.get_pressure()
pressure = round(pressure, 1)
pressure = str(pressure)
if pressure <= "995":
target1 = open('/var/www/meteodeep/weatherwarning.txt', 'w')
target1.write(pressure)
target1.close()
#account info
to = '[email protected]'
gmail_user = '[email protected]'
gmail_password = 'your_password'
smtpserver = smtplib.SMTP('smtp.gmail.com', 587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.login(gmail_user, gmail_password)
msgto='LOW PRESSURE WARNING:https://goo.gl/o4O70x'
msg=MIMEText(my_ip)
msg['Subject']= 'Weather Warning'
msg['From']= gmail_user
msg['To'] = to
smtpserver.sendmail(gmail_user, [to], msg.as_string())
smtpserver.quit()
elif pressure >= "996":
target1 = open('/var/www/meteodeep/weatherwarning.txt', 'w')
target1.write("No Current Weather Warning")
target1.close()
else:
print("ERROR")
from subprocess import call
Upload = "/home/pi/Dropbox-Uploader/dropbox_uploader.sh upload /var/www/meteodeep/weatherwarning.txt /WeatherWarning.txt"
call ([Upload], shell=True)
# crontab
# 0 * * * * sudo /usr/bin/python3 /var/www/meteodeep/LivePressure.py