-
-
Save egocks/e32f320af67edfbc0619 to your computer and use it in GitHub Desktop.
modified raspi-gmail.py; uses imaplib to accomplish the same goal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cat <<! > raspi-gmail.py | |
#!/usr/bin/env python | |
import RPi.GPIO as GPIO, imaplib, time | |
DEBUG = 1 | |
USERNAME = "username" # just the part before the @ sign, add yours here | |
PASSWORD = "password" | |
NEWMAIL_OFFSET = 1 # my unread messages never goes to zero, yours might | |
MAIL_CHECK_FREQ = 60 # check mail every 60 seconds | |
GPIO.setmode(GPIO.BCM) | |
GREEN_LED = 18 | |
RED_LED = 23 | |
GPIO.setup(GREEN_LED, GPIO.OUT) | |
GPIO.setup(RED_LED, GPIO.OUT) | |
M = imaplib.IMAP4_SSL('imap.gmail.com','993') | |
sessionValid = True | |
try: | |
M.login(USERNAME, PASSWORD) | |
print "LOGIN SUCCESS" | |
except imaplib.IMAP4.error,e: | |
print str(e) | |
print "LOGIN FAILED!!! " | |
sessionValid = False | |
while sessionValid: | |
M.select() | |
newmails = len(M.search(None, 'UnSeen')[1][0].split()) # from http://stackoverflow.com/a/3984850 | |
if newmails > NEWMAIL_OFFSET: | |
GPIO.output(GREEN_LED, True) | |
GPIO.output(RED_LED, False) | |
else: | |
GPIO.output(GREEN_LED, False) | |
GPIO.output(RED_LED, True) | |
time.sleep(MAIL_CHECK_FREQ) | |
! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment