The Idea
I wrote a post a while back about using Python to write Blogspot posts from the command line. It took me about two weeks to completely forget about it. Still, it’s one of the few posts on this blog that gets regular visits, and the code … well, the code is not great. It was a fair effort, but it didn’t even accomplish the things I had initially set out to do. Account information is hard-coded into the code, for example. I also blundered along haphazardly with parsing metadata information myself despite the fact that Python Markdown has an extension which is perfectly capable of handling metadata. Well, let’s look at that code again.
There’s a fresh install of Ubuntu 9.04 on my laptop and I’ve got projects I feel like talking about. So let’s get started.
The basic flow will be the same. Given a command line that looks like this:
- Load settings
- Create a HTML formatted string based on the Markdown-formatted text found in
post.txt
- Request that Blogger store the post using post data and user settings
- Report the result of the publish request.
I’ll be starting from the code that already exists in the earlier posts. We can start this project with confidence once we have everything set up and we’re sure the old code still does what we expect it to.
Setup
Ubuntu 9.04 already has a copy of Python 2.6 installed. I suppose I could grab a fresh copy of the Python source and build it myself, but I don’t really feel like it right now. Sometimes I’m just lazy. Ubuntu’s 2.6 will work well enough for my needs.
Modules are a different matter. I want fresh copies of Python Markdown and GData, rather than the somewhat dated modules that are available in the repository. There are a fair number of bug fixes and new features in the latest versions.
The Starting Code
Now that I have the most important dependencies installed, I can revisit the code from the first and second posts. There’s no local copy of the code, so I will just copy and paste the original code, run the tests, and share the starting code. What could possibly go wrong?
Ouch. Something has gone horribly wrong in copying and pasting the code from the posts, the module behaviors have changed, or maybe they never worked as well as I thought they did. Either way, this is bad. Let me fix these issues and then I’ll share the new starting code with you.
The New Starting Code
Coming Up Next
These posts will be short, since I want to get something up while still getting things done at work. We have our starting point reestablished, and next time we will be concentrating on loading user settings rather than embedding those details right in our code.