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
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?
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.