示例#1
0
文件: idle.py 项目: nfultz/setosa.vim
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)


while True:
    idle_res = imap.idle_check(timeout=idle_timeout)
    logging.info("Receive: " + str(idle_res))
    for res in idle_res:
        if res[1] == b"EXISTS": notify_new_mail()
示例#2
0
            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()