简体   繁体   English

Raspberry pi:我使用一些代码进行电子邮件警报,使用GPIO端口进行LED通知

[英]Raspberry pi: Im using Some code for a Email alert with use of the GPIO ports for LED notifications

Im using Python the RPi, and found some coding online that would notify me of emails that come in and light up an LED on the GPIO ports 我正在使用Python RPi,并在网上找到一些编码,通知我进来的电子邮件并点亮GPIO端口上的LED

Here is the code: 这是代码:

#!/usr/bin/env python

import RPi.GPIO as GPIO, feedparser, time

DEBUG = 1

USERNAME = ""
PASSWORD = ""

NEWMAIL_OFFSET = 1
MAIL_CHECK_FREQ = 60

GPIO.setmode(GPIO.BCM)
GREEN_LED = 18
RED_LED = 23
GPIO.setup (GREEN_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 have" newmails, "new emails!"

        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)


except KeyboardInterrupt:
    GPIO.cleanup()

And Python says that the " by the first print is invalid. Anyone know why? Python说“第一次打印是无效的。有人知道为什么吗?

Is this an exact copy-paste from the code on your machine? 这是您机器上代码的精确复制粘贴吗? It looks like you're missing a comma after "You have" and before newmails . 看起来你在"You have"和在新newmails之前错过了一个逗号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM