Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. #!/usr/bin/python
  2. # Raspberry Pi Zero in stock @ thepihut alarm for Rpi PC buzzer
  3. import RPi.GPIO as GPIO, feedparser, time
  4.  
  5. USERNAME = "" # Gmail User Name  
  6. PASSWORD = "" # Gmail Password
  7.  
  8. GPIO.setmode(GPIO.BOARD)
  9. pin = 12
  10. GPIO.setup(pin, GPIO.OUT)
  11. pwm=GPIO.PWM(pin, 500)
  12. pwm.start(0)
  13.  
  14. while True:
  15.     try:
  16.         found=False
  17.         cur_mails = feedparser.parse("https://" + USERNAME + ":" + PASSWORD +"@mail.google.com/gmail/feed/atom")
  18.         total=int(cur_mails["feed"]["fullcount"])
  19.         if total > 0:
  20.             for i in range(0,total):
  21.                 if cur_mails["entries"][i]["author_detail"]["email"] == "support@thepihut.com":
  22.                     title=cur_mails["entries"][i]["title"]
  23.                     if "Zero" in title or "zero" in title or "Stock" in title or "stock" in title:
  24.                         found=True
  25.         if found:
  26.             pwm.ChangeDutyCycle(50)
  27.         else:
  28.             pwm.ChangeDutyCycle(0)
  29.         time.sleep(60)
  30.     except Exception,e: # Probally a network conection error
  31.         print e
  32.         time.sleep(60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement