ghost_export 是为Ghost 导出博客文件的一个python小工具,ghost_exportpython,# -*- coding
文章由Byrx.net分享于2019-03-23 08:03:26
ghost_export 是为Ghost 导出博客文件的一个python小工具,ghost_exportpython,# -*- coding
# -*- coding:utf-8 -*-## ghost_export 是为Ghost 导出博客文件的一个python小工具,# 默认把ghost_export.py放在Ghost的根目录下,它就可以顺利工作了. # 导出 的目录为 post# created by Wasabi 2013-10-18## Version 0.1#import sqlite3import os,sys# 通常只要配置了ghost_path就可以了.# ghost 目录 ghost_path = './' # ghost_path = 'E:/webroot/demo/Ghost-0.3.2/'# db 目录db_path = ghost_path + 'content/data/ghost-dev.db'# 输出目录export_path = ghost_path +'post/'suffix = '.md'# 写入文件def create_file(filename, content): f = open(export_path+filename+suffix, 'w') f.write(content) f.close()# 主程序 def main(): # 如果不存在,就创建post 目录 if not os.path.exists(ghost_path + "post"): os.mkdir(ghost_path+"post") print db_path conn = sqlite3.connect(db_path) c = conn.cursor() c.execute("SELECT * FROM posts limit 1000") res = c.fetchall() for f in res: create_file(f[3],f[4]) conn.close()reload(sys) # 2sys.setdefaultencoding('utf-8') # 3# print sys.getdefaultencoding()main()print "export file to %s" % export_pathprint "Finish!";#该片段来自于http://byrx.net
评论关闭