Skip to content

Instantly share code, notes, and snippets.

@viko16
Created November 24, 2015 15:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viko16/6b6a973d8f285d74a951 to your computer and use it in GitHub Desktop.
Save viko16/6b6a973d8f285d74a951 to your computer and use it in GitHub Desktop.
从 Typecho 导出 Markdown #python
# encoding=utf8
import MySQLdb
import sys
import time
reload(sys)
sys.setdefaultencoding('utf8')
specialSign = "<!--markdown-->"
try:
conn = MySQLdb.connect(
host='localhost',
user='root',
passwd='root',
db='just-test',
port=3306,
charset='utf8'
)
cur = conn.cursor(MySQLdb.cursors.DictCursor)
cur.execute("SELECT * FROM typecho_contents WHERE type = '%s'" % 'post')
results = cur.fetchall()
for r in results:
content = r['text'].replace(specialSign, '', 1)
modifiedAt = time.strftime("%Y-%m-%d", time.localtime(r['modified']))
title = modifiedAt + '-' + r['title'].replace('/', ' or ')
output = open(title + '.md', 'wt')
output.write(content)
output.close()
print 'Done'
cur.close()
conn.close()
except MySQLdb.Error,e:
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
@note4
Copy link

note4 commented Sep 9, 2019

如果没有 <!--markdown--> 标记的内容会直接忽略?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment