Get total word count from WordPress blog with Python

I just came across this script by Jabba Laci to download your posts from WordPress.  It reminded me that I wanted to see how many words I have written to my blog so far.  Maybe it’s just because I’m still new to WordPress, but I haven’t seen a total word count anywhere. Here’s the modified script:

#!/usr/bin/env python
from __future__ import division
import xmlrpclib

MAX_POSTS = 100

server = xmlrpclib.ServerProxy('https://YOUR_BLOG_ADDRESS.wordpress.com/xmlrpc.php')
result = server.metaWeblog.getRecentPosts('YOUR_BLOG_ADDRESS', 'YOUR_USERNAME', 'YOUR_PASSWORD', MAX_POSTS)

numPosts = len(result)
numWords = 0
for post in result:
  numWords += len(post['description'].split())
avgWords = numWords/numPosts

print """Total Posts: %d
Total Words: %d
Avg Words: %d""" % (numPosts, numWords, avgWords)

And the output I get is:

Total Posts: 21
Total Words: 9731
Avg Words: 463

Which is slightly wrong because this simple script does not differentiate between drafts and posts (and my word counting routine is probably too naive among other things). A more correct and robust version of this is left as an exercise to the reader. I’m more than satisfied with this simple, rough estimate.