The Little Grasshopper

“iPhone 3D” In Stock At Amazon!

Amazon has replaced the Pre-order button for my book with Add to Cart. To celebrate, I created a word cloud of the entire book using and a python script. Here’s the word cloud:

Word cloud of 'iPhone 3D Programming'

I love that “API” got nestled into “ES”. To create the word cloud, I first ran a little python script against the book’s DocBook source. The script simply extracts content from para elements. If I don’t do this, the word cloud contains all the sample code and represents words like const in huge, overwhelming text. (I tried it, trust me.) Anyway here’s the script:

from xml.dom.minidom import parse
import codecs

def getText(nodelist):
    rc = ""
    for node in nodelist:
        if node.nodeType == node.TEXT_NODE:
            rc = rc +
    return rc

f = "wordle.txt", "w", "utf-8" )

for i in xrange(0, 10):
    filename = "ch%02d.xml" % i
    tree = parse(filename)
    paras = tree.getElementsByTagName("para")
    for para in paras:

print "wordle.txt has been dumped"

After running the script, I simply pasted the resulting text file into

Written by Philip Rideout

May 19th, 2010 at 2:42 pm

Posted in OpenGL,Python

Tagged with , , , ,