dasBlog and hierarchal categories

time to read 4 min | 632 words

Did you know that dasBlog has a hierarchal categories with a beautiful way to represent them? I didn't until I visited Oren Ellenbogen's blog and saw how his categories looked. My immediate response was "Me Too! Me Too!", so I set out to learn the secret.

Turns out that this isn't such a big secret after all: Oren* told me that it's simply a matter of seperating the categories with '|'. There is also some css magic that goes along with it, but looking at Oren's site with the WebDeveloper Extention for Firefox quickly showed what I needed. (#1 tool for anyone who wants to develop for the web, in my opinion).

I changed a single post category, and it worked! Now I wanted to change all the rest of them. Hierarchal categories are the new thing, I hear, so I certainly wanted them for my blog. Ever for the old posts. The trouble is that I currently has over 600 posts. (When did I manage to post so much?) And I wasn't feeling like spending the rest of the weekend pouring over each and every one of them changing the categories. I immediately setup to find a programmatic solution to the problem.

The first thing I thought about was that dsaBlog has a programming interface using the Blogger API, but I never worked with it. I googled for a little bit and found the Xml-Rpc.Net library, which incidently comes with a blogger API sample. But apperantly the Blogger API doesn't let you update the categories of a single post, at least not in any way that a very curosry will show. The MetaWeblog API does however, so I used that. I compiled newtelligence.DasBlog.Runtime.Proxies\BloggerAPIClientProxy.cs to an assembly I named dasBlogger.dll (I could've also used the dasBlog assemblies, but it would've taken time to build them, so I just compiled it seperatedly).

I tested it and it worked! Then I had the really hard part, thinking about how to map my categories to hierarchal structure. Here is the code I ended up with, very simple to write and understand. But it doesn't work.  The problem is that dasBlog only return the last 30 posts, no matter what value you pass to it. I'm going to email Scott about it. Pursuing the source for dasBlog, I didn't see where this functionality is controled.

import System
import CookComputing.XmlRpc
import newtelligence.DasBlog.Runtime.Proxies

user = "Ayende Rahien"
password = "Ayende Rahien's Password"

categories = {
"Ayende.Utilities" : "Programming | Utilities",
"Blog" : "Website | Blog",
"Boo" : "Programming | Boo",
"Boo On Rails" : "My Projects | Brail",
"Books" : "Culture | Books",
"Brail" : "My Projects | Brail",
"Bugs" : "Programming | Bugs",
"dasBlog" : "Website | Blog | dasBlog",
"Evil" : "Miscellaneous | Evil",
"eXtreme Programming" : "Programming | XP",
"Humor" : "Humor",
"Miscellaneous" : "Miscellaneous",
"Movies" : "Culture | Movies",
"Music" : "Culture | Music",
"NHibernate Query Analyzer" : "My Projects | NHibernate Query Analyzer",
"Programming" : "Programming",
"Rhino Mocks" : "My Projects | Rhino Mocks",
"Website" : "Website",
"Windows" : "Programming",
"Writings" : "Culture | Writings"
}
log = IO.File.CreateText("log.txt")
dasBlog = BloggerAPIClientProxy()
dasBlog.Url = "http://www.ayende.com/Blog/blogger.aspx"
posts = dasBlog.metaweblog_getRecentPosts("",user, password, 999)
start = DateTime.Now
for post in posts:
try:
for i in range( len (post.categories) ):
newCategory = categories[ post.categories[i] ]
if newCategory is null:
print "'${post.categories[i]}' is an unknown category"
continue
post.categories[i] = newCategory
if len(post.categories) == 0:
post.categories = ("Uncategorized",)
dasBlog.metaweblog_editPost(post.postid, user, password, post, true)
print "Updated post: ${post.title}"
except e:
print "Error updated post: ${post.title}"
print e.Message
log.WriteLine(e.ToString())
log.WriteLine("--- --- ---")
print "Took ${DateTime.Now - start}"

 * Last time I checked there were more than 8,500 people in Israel named Oren, and 7 named Oren Eini (none of them is related to me, btw).