Advertisement
Guest User

Untitled

a guest
Jun 30th, 2012
709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. # Hardware Gmail notifier for RPi
  2. # based on the notifier from Mitchtech
  3. # http://mitchtech.net/raspberry-pi-physical-gmail-notifier/
  4.  
  5. ## My LEDboard is common 3V3 wired (GPIO=True -> LED=Off)
  6. ## if your LEDboard is common GND you have to change all True into False and vice versa
  7.  
  8. from os.path import exists
  9. import RPi.GPIO as GPIO, feedparser
  10.  
  11. file=".unreadmail.txt"
  12.  
  13. # insert your username and password
  14. USERNAME="[USERNAME]@gmail.com"
  15. PASSWORD="[PASSWORD]"
  16.  
  17. # if .unreadmail.txt doesn't exists the script wont work
  18. # the following lines check if the file exists and create it if needed
  19. if exists(file) == False:
  20.         data = open(file, 'w')
  21.         data.write("0")
  22.         data.close()
  23.  
  24. # edit these two value depending on your pin wiring
  25. PIN_mail=7
  26. PIN_check=13
  27.  
  28.  
  29. data = open(file, 'r')
  30. status=int(data.read())
  31. data.close()
  32.  
  33. GPIO.setup(PIN_mail, GPIO.OUT)
  34. GPIO.setup(PIN_check, GPIO.OUT)
  35. GPIO.output(PIN_check, False)
  36.  
  37. # notification LED is turned on/off depending on .unreadmail.txt
  38. if status == 0:
  39.         GPIO.output(PIN_mail, True)
  40. else:
  41.         GPIO.output(PIN_mail, False)
  42.  
  43. # notification parsing
  44. newmails = int(feedparser.parse("https://" + USERNAME + ":" + PASSWORD + "@mail.google.com/gmail/feed/atom")["feed"]["fullcount"])
  45.  
  46. # output on .unreadmail.txt and GPIO
  47. data = open(file, 'w')
  48. if newmails > 0:
  49.         GPIO.output(PIN_mail, False)
  50.         data.write("1")
  51.  
  52. else:
  53.         GPIO.output(PIN_mail, True)
  54.         data.write("0")
  55.  
  56. GPIO.output(PIN_check, True)
  57. data.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement