Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Hardware Gmail notifier for RPi
- # based on the notifier from Mitchtech
- # http://mitchtech.net/raspberry-pi-physical-gmail-notifier/
- ## My LEDboard is common 3V3 wired (GPIO=True -> LED=Off)
- ## if your LEDboard is common GND you have to change all True into False and vice versa
- from os.path import exists
- import RPi.GPIO as GPIO, feedparser
- 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=7
- PIN_check=13
- 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)
- # notification LED is turned on/off depending on .unreadmail.txt
- if status == 0:
- GPIO.output(PIN_mail, True)
- else:
- GPIO.output(PIN_mail, False)
- # notification parsing
- 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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement