Skip to content

Instantly share code, notes, and snippets.

@lmacken
Created April 5, 2012 00:05
Show Gist options
  • Save lmacken/2306698 to your computer and use it in GitHub Desktop.
Save lmacken/2306698 to your computer and use it in GitHub Desktop.
Ports a pyblosxom 'entries' directory into blogofile markdown files
# Ports a pyblosxom 'entries' directory into blogofile markdown files
# Luke Macken <lmacken@redhat.com>
import os, stat, time
for old in os.listdir('entries'):
if old.startswith('comments') or old == 'LATEST':
continue
new = file('_posts/%s.html' % old.replace('.txt', ''), 'w')
mtime = time.localtime(os.stat('entries/%s' % old)[stat.ST_MTIME])
timestamp = time.strftime('%Y/%m/%d %H:%M:%S', mtime)
header = """---
title: %(title)s
date: %(date)s
categories: %(categories)s
---
"""
body = ''
data = {'date': timestamp}
for i, line in enumerate(file('entries/%s' % old).readlines()):
line = line.strip()
if i == 0:
data['title'] = '"%s"' % line
elif line.startswith('#tags'):
data['categories'] = ', '.join(line.replace('#tags ', '').split(',')).lower()
elif line.startswith('#mdate'):
continue
else:
body += line + '\n'
new.write(header % data)
new.write(body)
new.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment