PyBlogger 0.7 is out. It has a new function, listPosts(), which gets information (date created, user ID, post ID, and text) of recent posts. It also has an object model, Blog.py:

"""Object model for Blogger

This is a high-level object-oriented interface for blogger.py,
which defines all the available functions exposed by Blogger.com's
XML-RPC API.

Example:
>>> user = Blog.User("YOUR_BLOGGER_USERNAME", "YOUR_BLOGGER_PASSWORD")
>>> blogs = user.blogs                # list of all blogs
>>> for blog in blogs:
...     print "Blog ID:", blog.id     # internal Blogger.com blog ID
...     print "Blog name:", blog.name # title of blog
...     print "Blog URL:", blog.url   # base URL of blog

>>> blog = blogs[0]                   # get reference to user's first blog
>>> posts = blog.posts                # list of most recent posts (up to 20)
>>> for post in blog.posts:
...     print "Post ID:", post.postid        # internal Blogger.com post ID
...     print "Post date:", post.dateCreated # date created, in tuple format
...     print "Posted by:", post.userid      # internal Blogger.com user ID
...     print "Post text:", post.content     # text of post

>>> posts.append("Ping.")             # post new entry to blog
>>> len(posts)                        # count posts
>>> posts[-1].content = "Pong."       # edit text of most recent post
>>> del posts[-1]                     # delete most recent post

>>> html = blog.template.main         # get HTML of main blog entry template
>>> blog.template.main = html         # set HTML template for main blog entries
>>> html = blog.template.archiveIndex # get HTML of archive index template
>>> blog.template.archiveIndex = html # set HTML template for archive index
"""

I’m already working on a new version which will have better unit tests that can be run by anybody. The current unit tests work by actually calling the real Blogger.com server and then using urllib to check the results. There are several problems with this:

To solve these problems, I decided to start over from scratch and make my own fake XML-RPC server. I figured out how to override the crucial part of xmlrpclib to redirect it to my own transport class. It’s hard to explain (wow, I don’t usually say that), but the upshot of it is that blogger.py thinks that it’s communicating with the Blogger.com server, but in reality it’s communicating with a locally-defined class (part of the test suite) that acts like the Blogger.com server.

This has several advantages:

The downside, of course, is added complexity. I kept the fake server class as simple as possible, but it’s still extra code that could have its own set of bugs. If a unit test fails, is it because blogger.py is wrong or because the server class isn’t correctly serving up fake data? On the whole, though, I think the benefits are worth the added complexity. Nobody said good programming was easy.

§

Respond privately

I am no longer accepting public comments on this post, but you can use this form to contact me privately. (Your message will not be published.)



§

firehosecodeplanet

© 2001–9 Mark Pilgrim