-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-gmail.py
76 lines (62 loc) · 1.58 KB
/
check-gmail.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
import serial, sys, feedparser, time
#Settings - Change these to match your account details
USERNAME="YOUR EMAIL ADDRESS example bob@gmail.com"
PASSWORD="YOUR PASSWORD"
PROTO="https://"
SERVER="mail.google.com"
PATH="/gmail/feed/atom"
# PATH="/gmail/feed/atom/Bills" # for specific GMAIL label
SERIALPORT = "/dev/tty.usbmodemfd141" # Change this to your Arduino serial port!
# Set up serial port
try:
ser = serial.Serial(SERIALPORT, 9600)
except serial.SerialException:
print "no device connected - exiting"
sys.exit()
var = 1
while var == 1 : # This constructs an infinite loop
newmails = int(feedparser.parse(PROTO + USERNAME + ":" + PASSWORD + "@" + SERVER + PATH)["feed"]["fullcount"])
# Output data to serial port
if newmails == 1:
ser.write("a")
#ser.write("FLAG")
#print "some mail"
print newmails
if newmails == 2:
ser.write("b")
#ser.write("FLAG")
#print "some mail"
print newmails
if newmails == 3:
ser.write("c")
#ser.write("FLAG")
#print "some mail"
print newmails
if newmails == 4:
ser.write("d")
#ser.write("FLAG")
#print "some mail"
print newmails
if newmails == 5:
ser.write("e")
#ser.write("FLAG")
#print "some mail"
print newmails
if newmails == 6:
ser.write("f")
#ser.write("FLAG")
#print "some mail"
print newmails
if newmails > 6:
ser.write("m")
#print "no mail"
print newmails
if newmails == 0:
ser.write("n")
#print "no mail"
print newmails
#print data to terminal
time.sleep(10) # put a delay on the loop
# Close serial port
ser.close()
# RUN THIS SCRIPT TO SEND DATA TO ARDUINO