物理Gmail通知程序已启用

时间:2015-09-22 18:45:30

标签: python raspberry-pi email-notifications

所以我试图制作一个实体Gmail通知程序。当我有未读邮件时,使用330欧姆电阻和LED闪烁。事实证明这比我想象的更难。当我去执行python代码时,我一直得到这个输出。

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'

这是我使用的代码,当然会删除凭据。

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()

任何帮助都会受到赞赏,我是这方面的新手。

0 个答案:

没有答案