So I am pretty new to Python and hardware to software interactions. I need help with this bit of code that I revised off the web. My LED is not switching to red when there is no new emails... It seems to be understanding FeedParser is the issue, and I have NO idea how it works, so a brief explanation of what it is doing here would be greatly appreciated. I am not sure if the Parser is the error but I cannot see otherwise because I know whats going on with the rest of the code.
It's either my global "DEBUG" variable,
DEBUG = 1
"NEWMAIL_OFFSET"
NEWMAIL_OFFSET = 1
or the parser. I honestly believe it could be the DEBUG, but I tried switching things around. I cannot figure out what FeedParser is doing so it is a little too difficult to figure out. Google has been little help. Either talking japanese to me or not enough detail.. Finally, Here is my bit of code!:
cat <<! > raspi-gmail.py
#!/usr/bin/env python
import RPi.GPIO as GPIO, feedparser, time
DEBUG = 1
USERNAME = "***EMAIL***"
PASSWORD = "************"
NEWMAIL_OFFSET = 1 #unread offset global
MAIL_CHECK_FREQ = 60 #Checks mail every 30 seconds
GPIO.setmode(GPIO.BCM)
YELLOW_LED = 18
RED_LED = 23
GPIO.setup(YELLOW_LED, GPIO.OUT)
GPIO.setup(RED_LED, GPIO.OUT)
while True:
newmails = int(feedparser.parse("https://" + USERNAME + ":" + PASSWORD + "@mail.google.com/gmail/feed/atom")["feed"]["fullcount"])
if DEBUG:
print "You've got mail! ", newmails, "unread messages."
if newmails > NEWMAIL_OFFSET:
GPIO.output(YELLOW_LED, True)
GPIO.output(RED_LED, False)
else:
GPIO.output(YELLOW_LED, True)
GPIO.output(RED_LED, False)
time.sleep(MAIL_CHECK_FREQ)