<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Free Geek &#187; Python</title>
	<atom:link href="http://freegeek.in/blog/category/programming/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://freegeek.in/blog</link>
	<description>The Chronicles of Nerd-nia</description>
	<lastBuildDate>Fri, 03 Jun 2011 05:15:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Check GMail the Python way</title>
		<link>http://freegeek.in/blog/2006/07/check-gmail-the-python-way/</link>
		<comments>http://freegeek.in/blog/2006/07/check-gmail-the-python-way/#comments</comments>
		<pubDate>Mon, 31 Jul 2006 15:35:21 +0000</pubDate>
		<dc:creator>Baishampayan</dc:creator>
				<category><![CDATA[Google]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">https://g33k.wordpress.com/2006/07/31/check-gmail-the-python-way/</guid>
		<description><![CDATA[Swaroop posted a nifty Perl script to check GMail. The script basically parses an Atom feed of the latest 20 mails provided by Google. Since a Python hacker like Swaroop is dabbling in Perl, I thought it was my duty as a Python evangelist (or is it Pythangelist?) to show the people that the same [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.swaroopch.info/" title="Swaroop CH">Swaroop</a> <a href="http://www.swaroopch.info/archives/2006/07/31/check_gmail/" title="check_gmail">posted a nifty Perl script</a> to check GMail. The script basically parses an Atom feed of the latest 20 mails provided by <a href="http://google.com/" title="Google">Google</a>. Since a <a href="http://python.org/" title="Python">Python</a> hacker like Swaroop is dabbling in Perl, I thought it was my duty as a Python evangelist (or is it Pythangelist?) to show the people that the same thing can be achieved using Python with equal ease <img src='http://freegeek.in/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  The main code is around 50% of the total code. A large portion of the code is used for the pretty printing. Here it is &#8212;</p>
<pre>## check-gmail.py -- A command line util to check GMail -*- Python -*-

# ======================================================================
# Copyright (C) 2006 Baishampayan Ghose &lt;b.ghose@ubuntu.com&gt;
# 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 urllib             # For BasicHTTPAuthentication
import feedparser         # For parsing the feed
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 fill(text, width):
    '''A custom method to assist in pretty printing'''
    if len(text) &lt; width:
        return text + ' '*(width-len(text))
    else:
        return text

def readmail(feed):
    '''Parse the Atom feed and print a summary'''
    atom = feedparser.parse(feed)
    print ""
    print atom.feed.title
    print "You have %s new mails" % len(atom.entries)
    # Mostly pretty printing magic
    print "+"+("-"*84)+"+"
    print "| Sl.|"+" Subject"+' '*48+"|"+" Author"+' '*15+"|"
    print "+"+("-"*84)+"+"
    for i in xrange(len(atom.entries)):
        print "| %s| %s| %s|" % (
            fill(str(i), 3),
            fill(wrap(atom.entries[i].title, 50)[0]+"[...]", 55),
            fill(wrap(atom.entries[i].author, 15)[0]+"[...]", 21))
    print "+"+("-"*84)+"+"

if __name__ == "__main__":
    f = auth()  # Do auth and then get the feed
    readmail(f) # Let the feed be chewed by feedparser</pre>
<p>And here is a sample output &#8212;</p>
<pre>ghoseb@trinka:~$ python check-gmail.py
Enter username for New mail feed at mail.google.com: foo.bar
Enter password for foo.bar in New mail feed at mail.google.com:

Gmail - Inbox for foo.bar@gmail.com
You have 20 new mails
+------------------------------------------------------------------------------------+
| Sl.| Subject                                                | Author               |
+------------------------------------------------------------------------------------+
| 0  | Strip Whitespace Middleware[...]                       | Will McCutchen ([...]|
| 1  | [FOSS Nepal] list of free alternatives to windows[...] | Manish Regmi (r[...] |
| 2  | json serialization[...]                                | Gábor Farkas (g[...] |
| 3  | editable=False and "Could not find Formfield or[...]   | Corey (coordt@e[...] |
| 4  | IronPython 1.0 release candidate[...]                  | Jeremy Dunck (j[...] |
| 5  | django server tree organization[...]                   | Kenneth[...]         |
| 6  | Project when using multiple sites[...]                 | Jay Parlar (par[...] |
| 7  | [FOSS Nepal] Neprog (nepali version pogrammer for[...] | ujwal (ujwal2@g[...] |
| 8  | Bug#379789: wrong keymap on Intel MacBook Pro[...]     | Frans Pop (elen[...] |
| 9  | debconf is Level 1?[...]                               | Clytie Siddall ([...]|
| 10 | Weird slowdown with dev server behind nat[...]         | Akatemik (tpiev[...] |
| 11 | Database API question: I am not able to return a[...]  | DavidA (david.a[...] |
| 12 | Bug#379120: lspci present on i386, verify on[...]      | Eddy Petrişor ([...] |
| 13 | New levels of D-I[...]                                 | Eddy Petrişor ([...] |
| 14 | Installed Apps in settings.py[...]                     | limodou (limodo[...] |
| 15 | where u at man ... where can i call you ??????[...]    | Sanjeev[...]         |
| 16 | unable to runser ?[...]                                | Geert[...]           |
| 17 | Bug#380585: debian 3.1 install FD[...]                 | as_hojoe (as_ho[...] |
| 18 | Re: Translated packages descriptions progress[...]     | Michael Bramer ([...]|
| 19 | Loading an url takes 60 sec.[...]                      | and_ltsk (andre[...] |
+------------------------------------------------------------------------------------+
ghoseb@trinka:~$</pre>
<p>Well, the code is obviously pretty rough. It&#8217;s just for showing newbies how to use <a href="http://feedparser.org/" title="FeedParser">feedparser</a> and <a href="///usr/share/doc/python2.4-doc/html/lib/module-urllib.html" title="Urllib">urllib</a>, two very powerful Python libraries. Improvements, patches are welcome <img src='http://freegeek.in/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The <a href="http://people.ubuntu-in.org/~ghoseb/check-gmail.py" title="Check GMail">text source</a> can also be downloaded.</p>
]]></content:encoded>
			<wfw:commentRss>http://freegeek.in/blog/2006/07/check-gmail-the-python-way/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Started working on the Design</title>
		<link>http://freegeek.in/blog/2006/06/started-working-on-the-design/</link>
		<comments>http://freegeek.in/blog/2006/06/started-working-on-the-design/#comments</comments>
		<pubDate>Mon, 05 Jun 2006 21:28:15 +0000</pubDate>
		<dc:creator>Baishampayan</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[SoC]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">https://g33k.wordpress.com/2006/06/06/started-working-on-the-design/</guid>
		<description><![CDATA[After a prolonged sickness, I am back to work again. Started working on the design specs of the offline update tool today. It&#39;s still incomplete, but I am just putting up my ideas of implementation on the doc. Talked to Mario Danic about the design doc. He also approved my specification in the Launchpad Blueprint [...]]]></description>
			<content:encoded><![CDATA[<p>After a <a href="http://g33k.wordpress.com/2006/06/02/down-with-tooth-infection-and-fever/" title="I was sick for a week or two">prolonged sickness</a>, I am <a href="http://g33k.wordpress.com/2006/06/03/relief-at-last/" title="I am fine now">back to work</a> again. Started working on the <a href="https://wiki.ubuntu.com/OfflineUpdateSpec/DesignDiscussion" title="Design Specs">design specs</a> of the <a href="https://wiki.ubuntu.com/OfflineUpdateSpec/" title="Offline Update Tool">offline update tool </a>today. It&#39;s still incomplete, but I am just putting up my ideas of implementation on the doc. Talked to <a href="https://wiki.ubuntu.com/MarioDanic" title="Mario Danic">Mario Danic</a> about the design doc. He also approved my specification in the Launchpad Blueprint system.</p>
<p>I was quite relieved to know that <a href="http://sourceforge.net/projects/python-apt" title="Python-APT">python-apt</a> is quite usable and it works fine (though not being very pythonic in nature). I read somewhere that it&#39;s not very actively maintained now-a-days and lacks a lot of features. That info relieved me quite a lot, otherwise my whole app would have become jeopardised <img src='http://freegeek.in/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>There are people who are also requesting me to port the tool to Windows. Well, <a href="http://www.python.org/" title="Python.Org">Python</a> code is easily portable but hey, Windows has no APT library <img src='http://freegeek.in/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Thankfully Mario is writing a tool for Windows which does a similar job, so may be I will be able to borrow some ideas from him.</p>
<p>I also need to check if my bank accepts cheques in Indian Rupees but drawn in the USA. As I have heard, they may claim that such cheques are impossible &#8230; heh, they have no idea about <a href="http://www.google.com" title="Google">Google</a>!</p>
<p>Anyway, I need to sleep off now. I must finish the design doc by tomorrow.</p>
]]></content:encoded>
			<wfw:commentRss>http://freegeek.in/blog/2006/06/started-working-on-the-design/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

