Created
November 24, 2015 15:54
-
-
Save viko16/6b6a973d8f285d74a951 to your computer and use it in GitHub Desktop.
从 Typecho 导出 Markdown #python
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
# 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]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
如果没有
<!--markdown-->
标记的内容会直接忽略?