1 #!/usr/bin/env python
2 import sys
3 from urllib import urlopen
4 from BeautifulSoup import BeautifulSoup
5
6 # Yes, this could have been done with a standard XML parser, but BeautifulSoup
7 # is such a pleasant thing to use.
8
9 RSS_URL = 'http://%s.blogspot.com/feeds/posts/default?max-results=10000'
10
11 if len(sys.argv) != 2:
12 print "Displays a breakdown of post count by author for a blogspot blog."
13 print "usage: %s <blogname>" % sys.argv[0]
14 print " (e.g. %s myblog for http://myblog.blogspot.com)" % sys.argv[0]
15 sys.exit(1)
16
17 print 'Fetching %s' % (RSS_URL % sys.argv[1])
18 rss = urlopen(RSS_URL % sys.argv[1]).read()
19
20 print 'Parsing %d kb of XML' % (len(rss) / 1024)
21 soup = BeautifulSoup(rss)
22 entry_elems = soup('entry')
23 print '%d posts found' % len(entry_elems)
24
25 author_counts = {}
26 for entry in entry_elems:
27 author_name = entry('author')[0]('name')[0].string
28 author_counts[author_name] = author_counts.get(author_name, 0) + 1
29
30 author_tuples = author_counts.items()
31 author_tuples.sort(key=lambda t: -t[1])
32
33 print
34 print '%-40s %-10s' % ('Author', 'Posts')
35 print '%-40s %-10s' % ('-' * 40, '-' * 10)
36 for author, posts in author_tuples:
37 print '%-40s %-10s' % (author, posts)