<filename>mailcheck/mailcheck.py<gh_stars>10-100
# Python script to set a Playbulb LED colour based on the state of
# an IMAP mailbox.
# by <NAME>
# https://github.com/ianrenton/playbulb-tools
# Watch it in action: https://vimeo.com/119624218

import getpass, imaplib, os, time

#### Config ####

# Your IMAP server config
SERVER = 'imap.gmail.com'
PORT = 993
USER = 'yourusername'
PASSWORD = '<PASSWORD>'

# Your Playbulb address (obtained with 'sudo hcitool lescan')
PLAYBULB_ADDRESS = '01:23:45:67:89:01'

# Check every n seconds (300 = 5 mins)
CHECK_INTERVAL = 300

#### Code below ####
while True:
  M = imaplib.IMAP4_SSL(SERVER, PORT)
  M.login(USER, PASSWORD)
  M.select()
  unreadCount = len(M.search(None, 'UnSeen')[1][0].split())
  print str(unreadCount) + ' unread emails'
  
  if unreadCount == 0:
    # No unread, set to solid red
    os.system('gatttool -b ' + PLAYBULB_ADDRESS + ' --char-write -a 0x0016 -n 00FF0000')
  else:
    # Some unread, set to green and flash
    os.system('gatttool -b ' + PLAYBULB_ADDRESS + ' --char-write -a 0x0014 -n 0000FF0000001F00')
  time.sleep(CHECK_INTERVAL)
  
  M.close()
  M.logout()

<filename>mailcheck/mailcheck.py<gh_stars>10-100
# Python script to set a Playbulb LED colour based on the state of
# an IMAP mailbox.
# by <NAME>
# https://github.com/ianrenton/playbulb-tools
# Watch it in action: https://vimeo.com/119624218

import getpass, imaplib, os, time

#### Config ####

# Your IMAP server config
SERVER = 'imap.gmail.com'
PORT = 993
USER = 'yourusername'
PASSWORD = '<PASSWORD>'

# Your Playbulb address (obtained with 'sudo hcitool lescan')
PLAYBULB_ADDRESS = '01:23:45:67:89:01'

# Check every n seconds (300 = 5 mins)
CHECK_INTERVAL = 300

#### Code below ####
while True:
  M = imaplib.IMAP4_SSL(SERVER, PORT)
  M.login(USER, PASSWORD)
  M.select()
  unreadCount = len(M.search(None, 'UnSeen')[1][0].split())
  print str(unreadCount) + ' unread emails'
  
  if unreadCount == 0:
    # No unread, set to solid red
    os.system('gatttool -b ' + PLAYBULB_ADDRESS + ' --char-write -a 0x0016 -n 00FF0000')
  else:
    # Some unread, set to green and flash
    os.system('gatttool -b ' + PLAYBULB_ADDRESS + ' --char-write -a 0x0014 -n 0000FF0000001F00')
  time.sleep(CHECK_INTERVAL)
  
  M.close()
  M.logout()

# Python script to set a Playbulb LED colour based on the state of # an IMAP mailbox. # by <NAME> # https://github.com/ianrenton/playbulb-tools # Watch it in action: https://vimeo.com/119624218 #### Config #### # Your IMAP server config # Your Playbulb address (obtained with 'sudo hcitool lescan') # Check every n seconds (300 = 5 mins) #### Code below #### # No unread, set to solid red # Some unread, set to green and flash