#!/usr/bin/python import urllib # For BasicHTTPAuthentication import feedparser # For parsing the feed import pynotify # import ubuntu eye candy notification from textwrap import wrap # For pretty printing assistance _URL = "https://mail.google.com/gmail/feed/atom" 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 "You have %s new mails" % len(atom.entries) pynotify.init('GmailCheckPy') n = pynotify.Notification('Gmail.com', "You have %s new mails"%len(atom.entries)) n.show() if __name__ == "__main__": f = auth() # Do auth and then get the feed readmail(f) # Let the feed be chewed by feedparser