Gmail Widget

The following script will check an atom feed for your gmail account and output a command that can be piped to awesome-client to set the contents of a text box. For example, if you have 1 unread message, the script will output. The first argument to the script will be taken as the name of the widget you want the text to appear in.

Requires:
 * awesome-git
 * python
 * python-feedparser

Usage (the second line will be piped to awesome-client): 0 widget_tell mywidgetname 1
 * 1) checkgmail.py mywidgetname

Python script: import urllib import feedparser import sys _url = "https://mail.google.com/gmail/feed/atom" _pwd = "password" _username = "username" _widgetName = "emailbox" class GmailRSSOpener(urllib.FancyURLopener): def prompt_user_passwd(self, host, realm): return (_username, _pwd) def auth: opener = GmailRSSOpener f = opener.open(_url) feed = f.read return feed def getUnreadMsgCount(feed): atom = feedparser.parse(feed) newmails = len(atom.entries) return newmails if __name__ == "__main__": if len(sys.argv) > 1: _widgetName = sys.argv[1] feed = auth print "0 widget_tell %s %d" % (_widgetName, getUnreadMsgCount(feed))
 * 1) !/usr/bin/env python

In order to use this script to check your email regularly, you need a shell script like the following: sleep 5 while true; do    echo `checkgmail.py mywidget` sleep 120 done | awesome-client
 * 1) !/bin/bash
 * 2) sleep for 5 seconds before beginning in case awesome needs more time to set up

It might be useful, if you set a longer interval between checking messages, to set up your widget so that right clicking it immediately checks for new messages. And you can set left click to open gmail in your browser. textbox emailbox { text = "N/A" mouse { button = "1" command = "spawn" arg = "firefox www.gmail.com" }    mouse { button = "3" command = "spawn" arg = "echo `checkgmail.py emailbox` | awesome-client" } }
 * 1) In .awesomerc statusbar section