Created
March 5, 2016 11:35
-
-
Save pupboss/7d0619e25d847a477d05 to your computer and use it in GitHub Desktop.
All Ghost article to Hexo md
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
#!/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