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()
    f.close()
    cat = root[2:]
    print("""
<item>
<title>%s</title>
<content:encoded><![CDATA[%s]]></content:encoded>
<pubDate>%s</pubDate>
<wp:post_date>%s</wp:post_date>
<wp:status>publish</wp:status>
<dc:creator><![CDATA[clintonroy]]></dc:creator>
<category><![CDATA[%s]]></category>
<category domain="category" nicename="%s"><![CDATA[%s]]></category>
</item>
""" % (title,
linebreaks.sub(r'\1 \2', body),
ctime.strftime('%a, %d %b %Y %H:%M:%S +0000'), ctime.isoformat().replace('T', ' '),
cat, cat, cat))

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s


%d bloggers like this: