Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/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:
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:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment