我使用 Python 的 RPi,并在网上找到了一些编码,可以通知我收到的电子邮件并点亮 GPIO 端口上的 LED
这是代码:
#!/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()
而Python说“第一次打印是无效的。有人知道为什么吗?