Add e-mail alert segment

This commit is contained in:
Kim Silkebækken 2013-01-28 13:55:36 +01:00
parent bda7384aa7
commit 8c003c2683
5 changed files with 44 additions and 0 deletions

View File

@ -4,6 +4,8 @@
"black": 16,
"white": 231,
"brightred": 160,
"darkestblue": 24,
"darkblue": 31,
"mediumblue": 38,
@ -37,6 +39,7 @@
"date": { "fg": "gray8", "bg": "gray2" },
"time": { "fg": "gray10", "bg": "gray2", "attr": ["bold"] },
"time:divider": { "fg": "gray5", "bg": "gray2" },
"email_alert": { "fg": "white", "bg": "brightred", "attr": ["bold"] },
"hostname": { "fg": "black", "bg": "gray10", "attr": ["bold"] },
"weather": { "fg": "gray8", "bg": "gray0" },
"weather_temp_cold": { "fg": "weather_temp_cold", "bg": "gray0" },

View File

@ -4,6 +4,8 @@
"black": 16,
"white": 231,
"brightred": 160,
"darkestblue": 24,
"darkblue": 31,
"mediumblue": 38,
@ -37,6 +39,7 @@
"date": { "fg": "gray8", "bg": "gray2" },
"time": { "fg": "gray10", "bg": "gray2", "attr": ["bold"] },
"time:divider": { "fg": "gray5", "bg": "gray2" },
"email_alert": { "fg": "white", "bg": "brightred", "attr": ["bold"] },
"hostname": { "fg": "black", "bg": "gray10", "attr": ["bold"] },
"weather": { "fg": "gray8", "bg": "gray0" },
"weather_temp_cold": { "fg": "weather_temp_cold", "bg": "gray0" },

View File

@ -39,6 +39,15 @@
"highlight_group": ["time", "date"],
"divider_highlight_group": "time:divider"
},
{
"name": "email_imap_alert",
"before": "✉ ",
"priority": 10,
"args": {
"username": "",
"password": ""
}
},
{
"name": "hostname"
}

View File

@ -39,6 +39,15 @@
"highlight_group": ["time", "date"],
"divider_highlight_group": "time:divider"
},
{
"name": "email_imap_alert",
"before": "✉ ",
"priority": 10,
"args": {
"username": "",
"password": ""
}
},
{
"name": "hostname"
}

View File

@ -229,3 +229,23 @@ def network_load(interface='eth0', measure_interval=1, suffix='B/s', binary_pref
def virtualenv():
return os.path.basename(os.environ.get('VIRTUAL_ENV', '')) or None
@memoize(60, persistent=True)
def email_imap_alert(username, password, server='imap.gmail.com', port=993, folder='INBOX'):
import imaplib
import re
try:
mail = imaplib.IMAP4_SSL(server, port)
mail.login(username, password)
rc, message = mail.status(folder, "(UNSEEN)")
unread_count = re.search("UNSEEN (\d+)", message[0]).group(1)
except (imaplib.error, AttributeError):
return None
if not unread_count:
return None
return [{
'highlight_group': 'email_alert',
'contents': unread_count,
}]