SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2008-12-21 05:51:35

earle79
Member
Registered: 2008-12-16
Posts: 15

Gmail & Conky

## check-gmail.py -- A command line util to check GMail -*- Python -*-
## modified to display mailbox summary for conky

# ======================================================================
# Copyright (C) 2006 Baishampayan Ghose <b.ghose@ubuntu.com>
# Modified 2008 Hunter Loftis <hbloftis@uncc.edu>
# Time-stamp: Mon Jul 31, 2006 20:45+0530
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
# ======================================================================

import sys
import urllib             # For BasicHTTPAuthentication
import feedparser         # For parsing the feed
from textwrap import wrap

_URL = "https://mail.google.com/gmail/feed/atom"

uname = sys.argv[1]
password = sys.argv[2]
maxlen = sys.argv[3]

urllib.FancyURLopener.prompt_user_passwd = lambda self, host, realm: (uname, password)
    
def auth():
    '''The method to do HTTPBasicAuthentication'''
    opener = urllib.FancyURLopener()
    f = opener.open(_URL)
    feed = f.read()
    return feed

def readmail(feed, maxlen):
    '''Parse the Atom feed and print a summary'''
    atom = feedparser.parse(feed)
    print '${color}Mail: %s@gmail.com (%s new)\n' % (uname, len(atom.entries))
    for i in range(min(len(atom.entries), maxlen)):
        print ' ${color}"%s"' % atom.entries[i].title
        print '    ${color lightgrey}%s' % atom.entries[i].author
    if len(atom.entries) > maxlen:
        print ' ${color}more...'

if __name__ == "__main__":
    f = auth()  # Do auth and then get the feed
    readmail(f, int(maxlen)) # Let the feed be chewed by feedparser

Last edited by earle79 (2008-12-21 05:53:31)

Offline

Be excellent to each other!

#2 2008-12-21 07:50:09

corenominal
WRONG
From: Lincoln, UK
Registered: 2008-11-20
Posts: 5,131
Website

Re: Gmail & Conky

${font FreeSans:bold:size=12}${color 99CCFF}EMAIL${color}${font}
${hr}
GMAIL:$alignr${execpi 100 python ~conkyscripts/gmail/gmail_parser.py earlesimers@gmail.com password passwordhere}

Offline

#3 2008-12-21 11:41:46

Nik_Doof
#! Junkie
Registered: 2008-12-13
Posts: 361
Website

Re: Gmail & Conky

#!/usr/bin/python

Last edited by Nik_Doof (2008-12-21 11:43:38)

Offline

#4 2008-12-21 11:47:24

Nik_Doof
#! Junkie
Registered: 2008-12-13
Posts: 361
Website

Re: Gmail & Conky

I've created a modified version just to show the count of new mails.

Exec using

check-gmail.py <username> <password>
#!/usr/bin/python
## check-gmail.py -- A command line util to check GMail -*- Python -*-
## modified to display mailbox summary for conky
## modified to produce a count of new mail by Andrew Williams

# ======================================================================
# Copyright (C) 2006 Baishampayan Ghose <b.ghose@ubuntu.com>
# Modified 2008 Hunter Loftis <hbloftis@uncc.edu>
# Time-stamp: Mon Jul 31, 2006 20:45+0530
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
# ======================================================================

import sys
import urllib             # For BasicHTTPAuthentication
import feedparser         # For parsing the feed
from textwrap import wrap

_URL = "https://mail.google.com/gmail/feed/atom"

uname = sys.argv[1]
password = sys.argv[2]

urllib.FancyURLopener.prompt_user_passwd = lambda self, host, realm: (uname, password)

def auth():
    '''The method to do HTTPBasicAuthentication'''
    opener = urllib.FancyURLopener()
    f = opener.open(_URL)
    feed = f.read()
    return feed

def readmail(feed):
    '''Parse the Atom feed and print a summary'''
    atom = feedparser.parse(feed)
    print '%s new\n' % len(atom.entries)

if __name__ == "__main__":
    f = auth()  # Do auth and then get the feed
    readmail(f) # Let the feed be chewed by feedparser

Offline

#5 2008-12-21 20:18:27

earle79
Member
Registered: 2008-12-16
Posts: 15

Re: Gmail & Conky

~conkyscripts/gmail/gmail_parser.py

Last edited by earle79 (2008-12-21 20:21:41)

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: acrobat

Debian Logo