1

So I was trying to make a physical Gmail notifier . Using a 330 ohm resistor and an LED to blink when I have unread mail. This is proving to be tougher then I thought. I keep getting this output when I go to execute the python code.

raspi_gmail.py:34: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
      GPIO.setup(PIN_mail, GPIO.OUT)
    Traceback (most recent call last):
      File "raspi_gmail.py", line 45, in <module>
        newmails = int(feedparser.parse("https://" + USERNAME + ":" + PASSWORD + "@mail.google.com/gmail/feed/atom")["feed"]["fullcount"])
      File "/usr/local/lib/python2.7/dist-packages/feedparser.py", line 356, in __getitem__
        return dict.__getitem__(self, key)
    KeyError: 'fullcount'

This is the Code I'm using , with the credentials cut out of course.

from os.path import exists
import RPi.GPIO as GPIO, feedparser
GPIO.setmode(GPIO.BCM)

file=".unreadmail.txt"

# insert your username and password
USERNAME="[USERNAME]@gmail.com"
PASSWORD="[PASSWORD]"

# if .unreadmail.txt doesn't exists the script wont work
# the following lines check if the file exists and create it if needed
if exists(file) == False:
        data = open(file, 'w')
        data.write("0")
        data.close()

# edit these two value depending on your pin wiring
PIN_mail=6
PIN_check=18


data = open(file, 'r')
status=int(data.read())
data.close()

GPIO.setup(PIN_mail, GPIO.OUT)
GPIO.setup(PIN_check, GPIO.OUT)
GPIO.output(PIN_check, False)


if status == 0:
        GPIO.output(PIN_mail, True)
else:
        GPIO.output(PIN_mail, False)


newmails = int(feedparser.parse("https://" + USERNAME + ":" + PASSWORD + "@mail.google.com/gmail/feed/atom")["feed"]["fullcount"])

# output on .unreadmail.txt and GPIO
data = open(file, 'w')
if newmails > 0:
        GPIO.output(PIN_mail, False)
        data.write("1")

else:
        GPIO.output(PIN_mail, True)
        data.write("0")

GPIO.output(PIN_check, True)
data.close()

Any help would be appreciated , I'm kind of a newbie to this whole aspect.

Robᵩ
  • 163,533
  • 20
  • 239
  • 308
  • Can you print out `feedparser.parse("https://" + USERNAME + ":" + PASSWORD + "@mail.google.com/gmail/feed/atom")["feed"]` ? – John Sep 22 '15 at 19:59
  • How would I go about doing that ? – Mike Katzakis Sep 22 '15 at 23:29
  • Your first warning is due to the GPIO port being already bound when you last ran your program. You can resolve this issue by adding GPIO.cleanup() to the bottom of your application (http://raspi.tv/2013/rpi-gpio-basics-3-how-to-exit-gpio-programs-cleanly-avoid-warnings-and-protect-your-pi) – blearn Sep 23 '15 at 01:05
  • After further research , it seems like the feedparser module is outdated. Now everyone uses Imap I suppose. – Mike Katzakis Sep 24 '15 at 13:19

0 Answers0