Skip to content

Instantly share code, notes, and snippets.

@sampsyo
Created February 21, 2014 18:52
Show Gist options
  • Save sampsyo/9140753 to your computer and use it in GitHub Desktop.
Save sampsyo/9140753 to your computer and use it in GitHub Desktop.
import re
import sys
import os
for path in sys.argv[1:]:
with open(path) as f:
contents = f.read()
m = re.search(r'created_at: (.*)', contents)
d, m, y = map(int, m.group(1).split('/'))
fn = os.path.basename(path)
base, _ = fn.split('.')
newfn = '{:04d}-{:02d}-{:02d}-{}.md'.format(y, m, d, base)
print('{} -> {}'.format(fn, newfn))
new_contents = re.sub(r'created_at: .*', 'layout: post', contents)
with open(newfn, 'w') as f:
f.write(new_contents)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment