Advertisement
Guest User

Untitled

a guest
Jan 26th, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. GNU nano 2.2.6 File: Gmailnot.py
  2. #!/usr/bin/env python
  3.  
  4. from imapclient import IMAPClient
  5. from piglow import PiGlow
  6. from time import sleep
  7. import time
  8. piglow = PiGlow()
  9.  
  10.  
  11. DEBUG = True
  12.  
  13. HOSTNAME = 'imap.gmail.com'
  14. USERNAME = '***********@gmail.com'
  15. PASSWORD = '********'
  16. MAILBOX = 'Inbox'
  17.  
  18. NEWMAIL_OFFSET = 0 # Unread offset
  19. MAIL_CHECK_FREQ = 30 # Frequency
  20.  
  21.  
  22.  
  23. def loop():
  24. server = IMAPClient(HOSTNAME, use_uid=True, ssl=True)
  25. server.login(USERNAME, PASSWORD)
  26.  
  27. if DEBUG:
  28. print('Logging in as ' + USERNAME)
  29. select_info = server.select_folder(MAILBOX)
  30. print('%d messages in INBOX' % select_info['EXISTS'])
  31.  
  32. folder_status = server.folder_status(MAILBOX, 'UNSEEN')
  33. newmails = int(folder_status['UNSEEN'])
  34.  
  35. if DEBUG:
  36. print "You have", newmails, "new emails!"
  37.  
  38. if newmails > NEWMAIL_OFFSET:
  39. piglow.all(1)
  40. sleep(1)
  41. piglow.all(50)
  42. sleep(1)
  43. piglow.all(1)
  44. sleep(1)
  45. piglow.all(50)
  46. sleep(1)
  47. piglow.all(1)
  48. else:
  49. piglow.all(0)
  50.  
  51. time.sleep(MAIL_CHECK_FREQ)
  52.  
  53. if __name__ == '__main__':
  54. try:
  55. print 'Press Ctrl-C to quit.'
  56. while True:
  57. loop()
  58. finally:
  59. print("loop")
  60.  
  61.  
  62. #Alfie T Tuesday 6th October
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement