helm/os/+arch/.config/polybar/modules/mail

29 lines
719 B
Plaintext
Raw Normal View History

2017-04-26 15:52:37 -07:00
#!/usr/bin/python
import imaplib
import os
import sys
ICON = ""
CONFIG_FILE = os.path.expanduser("~/.private/config/email")
COLOR_HL = "B48EAD"
COLOR_NONE = "65737E"
COLOR_ERR = "D08770"
n = 0
if os.path.isfile(CONFIG_FILE):
with open(CONFIG_FILE) as fp:
for line in fp:
addr, pwd = line.strip().split(",")
obj = imaplib.IMAP4_SSL('imap.gmail.com', 993)
obj.login(addr, pwd)
obj.select()
n += len(obj.search(None, 'UnSeen')[1][0].split())
obj.close()
obj.logout()
print("%{{F#{}}}{} {}".format(COLOR_HL if n > 0 else COLOR_NONE, ICON, n))
else:
print("%{{F#{}}}{} -".format(COLOR_ERR, ICON))
sys.exit(1)