-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemperature_notification.py
46 lines (38 loc) · 1.71 KB
/
temperature_notification.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
__author__ = 'joerod'
import serial,time,smtplib,tweepy,email.utils
from time import strftime
from email.mime.text import MIMEText
ser = serial.Serial('/dev/tty.usbmodem5d11', 9600)
while True:
print ser.readline()
with open('/Volumes/JoeRod/joerod/Desktop/temp.txt', 'w') as f:
f.write(ser.readline())
subject = 'The temperature is currently %s' %(ser.readline())
#sends email
text = 'Temperature was taken at %s' % (strftime("%m/%d/%Y %H:%M"))
msg = MIMEText(text)
msg['To'] = email.utils.formataddr(('Joe Rodriguez', '[email protected]'))
msg['From'] = email.utils.formataddr(('JoeRod Temperature', '[email protected]'))
msg['Subject'] = subject
# Credentials (if needed)
username = '[email protected]'
password = ''
# The actual mail send
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username,password)
server.sendmail('[email protected]', ['[email protected]'], msg.as_string())
server.quit()
#sends tweet with temperature
#enter the corresponding information from your Twitter application:
CONSUMER_KEY = ''#keep the quotes, replace this with your consumer key
CONSUMER_SECRET = ''#keep the quotes, replace this with your consumer secret key
ACCESS_KEY = ''#keep the quotes, replace this with your access token
ACCESS_SECRET = ''#keep the quotes, replace this with your access token secret
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
tweet = subject + ' at ' + strftime("%m/%d/%Y %H:%M")
api.update_status(tweet)
#Waits an hour before resending info
time.sleep(3600)