0

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)
MrRoss
  • 35
  • 10

1 Answers1

0

Well,

if newmails > NEWMAIL_OFFSET:
    GPIO.output(YELLOW_LED, True)
    GPIO.output(RED_LED, False)    # <=

else:
    GPIO.output(YELLOW_LED, True)        # Fix: make it False!
    GPIO.output(RED_LED, False)    # <=  # Fix: make it True!

If you have email, you turn the red light off; if you don't have email, you turn the red light off again!

Why would you expect it to turn on?

Hugh Bothwell
  • 55,315
  • 8
  • 84
  • 99
  • Hahaha, I JUST FOUND THAT! I also took debug out and added the line to YELLOW_LED/True so DEBUG wasn't procing the 0 messages a billion times and added blinking. So I put if newmails > NEWMAIL_OFFSET: print "youve got mail"... – MrRoss Jan 23 '15 at 22:06
  • Totally a noob mistake. Thank you :) – MrRoss Jan 23 '15 at 22:07