Skip to content

Instantly share code, notes, and snippets.

@viko16 viko16/export.py
Created Nov 24, 2015

Embed
What would you like to do?
从 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

This comment has been minimized.

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
You can’t perform that action at this time.