print "Script loaded" import serial, sys, feedparser, time #Settings - Change these to match your account details USERNAME="EMAIL@gmail.com" PASSWORD="*******" PROTO="https://" SERVER="mail.google.com" PATH="/gmail/feed/atom" SERIALPORT = "COM3" # Change this to your serial port! # Set up serial port try: ser = serial.Serial(SERIALPORT, 9600) except serial.SerialException: print "no device connected - exiting" sys.exit() newmails = int(feedparser.parse(PROTO + USERNAME + ":" + PASSWORD + "@" + SERVER + PATH)["feed"]["fullcount"]) print newmails # Output data to serial port if newmails > 0: ser.write('m') else: ser.write('n') # Close serial port ser.close()