request_raw = sys.stdin.readline() request = json.loads(request_raw.rstrip()) logging.info( {key: request[key] for key in request if key not in ["imap-passwd"]}) host = request["imap-host"] port = request["imap-port"] login = request["imap-login"] passwd = request["imap-passwd"] idle_timeout = request["idle-timeout"] imap = IMAPClient(host, port) imap.login(login, passwd) imap.select_folder("INBOX") imap.idle() def notify_new_mail(): title = "Iris" msg = "New mail available!" if sys.platform == "darwin": cmd = ["terminal-notifier", "-title", title, "-message", msg] else: cmd = ["notify-send", title, msg] logging.info("Notify: " + " ".join(cmd)) subprocess.Popen(cmd)
bulb = flux_led.WifiLedBulb(address) bulb.setRgb(colors, True, None) else: for address in bulb_address_list: logger.info(colors) bulb = flux_led.WifiLedBulb(address) bulb.setCustomPattern(colors, 100, "jump") bulb_addresses = bulb_scan() logger.info(bulb_addresses) open_config() server = IMAPClient(host) server.login(user, password) server.select_folder('INBOX') server.idle() while True: try: response = server.idle_check(timeout=15) if response: server.idle_done() text = pull_email() if text is not None: units = find_units(text[3]) set_pattern(units, bulb_addresses) except Exception as e: logging.error(str(e)) server.idle_done()