This Blog continues on

Friday, March 16, 2007

Posting to from the command line

Well, you can tell I am procrastinating working today (but you can forgive me after the PIDA GSoc Application was rejected as a mentoring organisation), but I have hacked up an early version of a library (for Python) to manage posting.

I was becoming slightly upset with, since it does some insane things like puts BR tags in the middle of PRE elements, which meant the syntax highlighting script I wanted to use was going nuts. I also gradually realised that none of the blogging clients work with the "new" although for me (who has only been blogging a few months) it has been the "only".

So, with a quick search around for documentation from, I was able to discover that uses the google GData API with a bit of Atom mixed in. I have no real ideas about these specifications, but explains it. Note that another document I found: seems depracated, but I can't confirm that at all.

Python is my language of choice for these things, so I started hacking.

Step 1: Authenticate with Google Login stuff. This is explained in but basically you need to:

  • Send a post request to
  • Set the service value of the data to "blogger" (this had me for a while)
  • Parse the body of the response for an "Auth" token
  • Include the header Authorization: GoogleLogin auth=yourAuthValue in all your requests from thereon in (not obvious from the authentication docs)
Once you have successfully logged in you will want to get some information. Firstly the posting API works on the blog ID, not the blog name. The ID appears in the source of the blog page in this tag <link rel="" type="application/atom+xml" ... but you can also fetch it from the blog's feed from the blog's name (see the API documentation).

Once you have this ID, posting is a matter of using the ID with your auth token, and entering data in an XML format as the post's body. Not forgetting to set the correct content-type for your post to "application/atom+xml". If you have posted correctly, the server returns a 201 Created response.

I have spared you the boring details of making urllib/urllib2 work with these things, but I have written some sample code and a command line client which you can browse online here: as well as accessing the googlecode page (no releases yet) here:

An example:

>>> from gblogger.client import BlogClient
>>> import getpass
>>> passwd = getpass.getpass()
>>> c = BlogClient('my-test-atom-blog', '', passwd)
>>>'this is a test post', 'this is the body of the test post with some html')
HTTP Error 201: Created
You can actually see this post online (if I haven't deleted the test blog) here:

Since I never have any spare time, my plans for this library are a bit shaky. It is a toy library in that there are no real tests, and failure conditions are not really dealt with properly. Ideally I will:

  1. Write a PIDA plugin for blogging
  2. Merge it into something like BloGTK, or write a miniature gui client of my own.

I have no idea how to publicize this to the community, but if any of you big Blogger admins or google developers are interested in spreading the word, (or silencing the word!) please let me know.

(some more useful links)


Well, editing now works in the library! I know this because I accidentally overwrote this post! Lucky for the unnoficial planet python it was still lying around there!