Changes

Students/Tiffany Lee

3,636 bytes added, 12:02, 18 March 2010
Python Code
===Python Code===
import urllib2, re, serial, sys, time
 
#Serial port for USB
SERIALPORT=3
 
#Gmail Account Details, this is only for GMAIL by the way.
USERNAME1="EMAIL@EMAIL.COM"
PASSWORD1="PASSWORD"
USERNAME2="EMAIL@EMAIL.COM"
PASSWORD2="PASSWORD"
USERNAME3="EMAIL@EMAIL.com"
PASSWORD3="PASSWORD"
PROTO="http://"
SERVER="mail.google.com"
PATH="/gmail/feed/atom"
while True:
print "checking email"
#get Atom feed 1
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, SERVER, USERNAME1, PASSWORD1)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
page = urllib2.urlopen(PROTO + SERVER + PATH)
#mail count line
for line in page:
count = line.find("fullcount")
if count > 0: break
newmails1 = int(re.search('\d+', line).group())
 
#get Atom feed 2
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, SERVER, USERNAME2, PASSWORD2)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
page = urllib2.urlopen(PROTO + SERVER + PATH)
#mail count line
for line in page:
count = line.find("fullcount")
if count > 0: break
newmails2 = int(re.search('\d+', line).group())
#newmails2 = 0
 
#get Atom feed 3
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, SERVER, USERNAME3, PASSWORD3)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
page = urllib2.urlopen(PROTO + SERVER + PATH)
#mail count line
for line in page:
count = line.find("fullcount")
if count > 0: break
newmails3 = int(re.search('\d+', line).group())
#newmails3 = 0
 
newmails = newmails1 + newmails2 + newmails3
print "number of new emails:", newmails
if newmails > 0:
try:
ser = serial.Serial(SERIALPORT, 57600)
print "connection open "
time.sleep(1.5)
 
#all emails have new mails
if newmails1>0 and newmails2>0 and newmails3>0:
print "A is sent"
msg = 'A'
#mail 2 has mail
elif newmails1 == 0 and newmails2 > 0 and newmails3 == 0:
print "B is sent"
msg = 'B'
#mail 1 has mail
elif newmails1 > 0 and newmails2 == 0 and newmails3 == 0:
print "C is sent"
msg = 'C'
#mail 3 has mail
elif newmails1 == 0 and newmails2 == 0 and newmails3 > 0:
print "D is sent"
msg = 'D'
#mail 1 and 2 has mail
elif newmails1 > 0 and newmails2 > 0 and newmails3 == 0:
print "E is sent"
msg = 'E'
#mail 2 and 3 has mail
elif newmails1 == 0 and newmails2 > 0 and newmails3 > 0:
print "F is sent"
msg = 'F'
#mail 1 and 3 has mail
elif newmails1 > 1 and newmails2 == 0 and newmails3 > 0:
print "G is sent"
msg = 'G'
ser.write(msg)
print "sending data "
time.sleep(3)
ser.close()
print "connection close "
time.sleep(1)
except serial.SerialException:
#sys.exit()
#print"something bad happens \n"
break
else :
time.sleep(1)
print "program ended\n"
===Arduino Code===
100
edits