Skip to content

Instantly share code, notes, and snippets.

@jinie
Created April 20, 2016 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jinie/ef5ac2f7479d89df3fffdc104ea4c5a6 to your computer and use it in GitHub Desktop.
Save jinie/ef5ac2f7479d89df3fffdc104ea4c5a6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import json
import sys
import datetime
import os.path
with open(sys.argv[1]) as f:
data = json.load(f)
output_dir = './output'
if os.path.exists(output_dir) == False:
os.mkdir(output_dir)
for post in data['db'][0]['data']['posts']:
created_at = datetime.datetime.fromtimestamp(post["created_at"]/1000).isoformat() + "Z"
title = post['title'].replace('\\','\\\\').replace('"','\"')
slug = post["slug"]
markdown = post["markdown"]
draft = 'true' if post["published_at"] == None else 'false'
published_at = created_at if post['published_at'] is None else datetime.datetime.fromtimestamp(post['published_at']/1000).isoformat() + 'Z'
output = '+++\n'
for k,v in (('date',published_at),('title',title),('slug',slug),('draft',draft)):
output += "{0} = \"{1}\"\n".format(k,v)
output += '+++\n'
output += markdown
outfile = os.path.join(output_dir,"{0}.md".format(slug))
with open(outfile,'w') as o:
o.write(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment