Created
April 5, 2012 00:05
-
-
Save lmacken/2306698 to your computer and use it in GitHub Desktop.
Ports a pyblosxom 'entries' directory into blogofile markdown files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ports a pyblosxom 'entries' directory into blogofile markdown files | |
# Luke Macken <[email protected]> | |
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