Migrate from blosxom to WordPress

Not perfect, but gets me most of the way there:

#!/usr/bin/env python3.1

import cgi, datetime, os, re
from os.path import join, getsize

linebreaks = re.compile(r'([^\n])\n([^\n])')

for root, dirs, files in os.walk('.'):
for name in files:
  if name.endswith('.txt'):
    fullname = os.path.join(root,name)
    ctime = datetime.datetime.fromtimestamp(os.path.getmtime(fullname))
    f = open(fullname)
    title = f.readline().strip()
    _blank = f.readline()
    body = f.read().strip()
    cat = root[2:]
<category domain="category" nicename="%s"><![CDATA[%s]]></category>
""" % (title,
linebreaks.sub(r'\1 \2', body),
ctime.strftime('%a, %d %b %Y %H:%M:%S +0000'), ctime.isoformat().replace('T', ' '),
cat, cat, cat))


2 Responses to “Migrate from blosxom to WordPress”

  1. Russell Stuart Says:

    It would be nice if your entries carried a title other than “clintonroy” on planet.humbug.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: