Skip to content

Instantly share code, notes, and snippets.

@pupboss
Created March 5, 2016 11:35
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 pupboss/7d0619e25d847a477d05 to your computer and use it in GitHub Desktop.
Save pupboss/7d0619e25d847a477d05 to your computer and use it in GitHub Desktop.
All Ghost article to Hexo md
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sqlite3
import time, datetime
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
cx = sqlite3.connect("/path/to/ghost.db")
cu = cx.cursor()
cu.execute("select title, slug, markdown, published_at from posts")
cx.commit()
arr = list(cu.fetchall())
path = "/path/"
def save(filename, contents):
fh = open(filename, 'w')
fh.write(contents)
fh.close()
for cell in arr:
content = """---\ntitle: """ + cell[0] + """\ndate: """ + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(cell[3]/1000)) + """\n---\n""" + cell[2]
save(path+cell[1]+'.md', content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment