Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/opt/local/bin/python2.6
- import feedparser
- import httplib2
- import re
- import sys
- BASE_FEED_URL = 'http://buzz.googleapis.com/feeds/%s/public/posted'
- HTTP = httplib2.Http("/tmp/httplib2-cache")
- def parse_feed(feed_url):
- response, content = HTTP.request(feed_url, "GET")
- assert response.status == 200
- return feedparser.parse(content)
- def main(argv):
- if len(argv) != 2:
- print 'Usage: buzz_feed.py username'
- return 1
- feed = parse_feed(BASE_FEED_URL % argv[1])
- total_posts = len(feed.entries)
- total_words = 0
- total_chars = 0
- total_replies = 0
- total_reply_words = 0
- total_reply_chars = 0
- total_newlines = 0
- reply_authors = set()
- for entry in feed.entries:
- total_words += len(re.split('\W+', entry.content[0].value))
- total_chars += len(entry.content[0].value)
- total_replies += int(entry.total)
- total_newlines += entry.content[0].value.count('\n')
- for link in entry.links:
- if link.rel == 'replies':
- reply_feed = parse_feed(link.href)
- for reply in reply_feed.entries:
- total_reply_words += len(re.split('\W+', reply.content[0].value))
- total_reply_chars += len(reply.content[0].value)
- reply_authors.add(reply.author)
- print 'Number of posts: %d' % total_posts
- print 'Total words in %d posts: %d' % (total_posts, total_words)
- print 'Total characters: %d' % total_chars
- print 'Total newlines: %d' % total_newlines
- print 'Average words per post: %d' % (total_words / total_posts)
- print 'Average chars per post: %d' % (total_chars / total_posts)
- print 'Total replies: %d' % total_replies
- print 'Average number of replies: %d' % (total_replies / total_posts)
- print 'Average number of words per reply: %d' % (total_reply_words / total_replies)
- print 'Average number of characters per reply: %d' % (total_reply_chars / total_replies)
- print 'Number of unique authors replying: %d' % len(reply_authors)
- if __name__ == '__main__':
- main(sys.argv)
Advertisement
Add Comment
Please, Sign In to add comment