Advertisement
Guest User

Untitled

a guest
Jul 14th, 2012
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Hardware Gmail notifier for RPi (updated for RPi.GPIO 0.3.1a)
  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. GPIO.setmode(GPIO.BOARD)
  11.  
  12. file=".unreadmail.txt"
  13.  
  14. # insert your username and password
  15. USERNAME="[USERNAME]@gmail.com"
  16. PASSWORD="[PASSWORD]"
  17.  
  18. # if .unreadmail.txt doesn't exists the script wont work
  19. # the following lines check if the file exists and create it if needed
  20. if exists(file) == False:
  21.         data = open(file, 'w')
  22.         data.write("0")
  23.         data.close()
  24.  
  25. # edit these two value depending on your pin wiring
  26. PIN_mail=7
  27. PIN_check=13
  28.  
  29.  
  30. data = open(file, 'r')
  31. status=int(data.read())
  32. data.close()
  33.  
  34. GPIO.setup(PIN_mail, GPIO.OUT)
  35. GPIO.setup(PIN_check, GPIO.OUT)
  36. GPIO.output(PIN_check, False)
  37.  
  38. # notification LED is turned on/off depending on .unreadmail.txt
  39. if status == 0:
  40.         GPIO.output(PIN_mail, True)
  41. else:
  42.         GPIO.output(PIN_mail, False)
  43.  
  44. # notification parsing
  45. newmails = int(feedparser.parse("https://" + USERNAME + ":" + PASSWORD + "@mail.google.com/gmail/feed/atom")["feed"]["fullcount"])
  46.  
  47. # output on .unreadmail.txt and GPIO
  48. data = open(file, 'w')
  49. if newmails > 0:
  50.         GPIO.output(PIN_mail, False)
  51.         data.write("1")
  52.  
  53. else:
  54.         GPIO.output(PIN_mail, True)
  55.         data.write("0")
  56.  
  57. GPIO.output(PIN_check, True)
  58. data.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement