Sunday, February 10, 2013

Check GMail script for Conky on Crunchbang Waldorf

I'm trying out Crunchbang Waldorf. I found a script for Crunchbang Statler (the previous version) that displayed the number of my new GMail messages in my Conky desktop display, but it didn't work with Waldorf. I was looking around for a simple and efficient script and eventually found one that works on the Arch Linux forum.


 I modified it a little not to show the number of emails on the server, just the number of new emails.
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import sys, imaplib

port = 993
server = 'imap.gmail.com'

username = 'name@gmail.com'
passwd = 'password'

imap_server = imaplib.IMAP4_SSL(server, port)
try:
    imap_server.login(username, passwd)
except:
    print('?? new')
    sys.exit( 1 )

typ, data = imap_server.select ('Inbox', True)
if typ == 'OK':
    total = int(data[0])
    typ, data = imap_server.search (None, 'SEEN')
    if typ == 'OK':
        seen = len(data[0].split())
        print('{} new'.format(total - seen))

if typ != 'OK':
    print('?? new')

imap_server.logout()
 Credit: rockin turtle.

No comments:

Post a Comment