数据迁移回来了

数据是迁移回来了。
利用 python 对原数据库扫描然后直接生成 markdown 文件
除了 tag 其他都取回来了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import sqlite3 as db
import time
import sys
reload(sys)
sys.setdefaultencoding("utf8")
def scan():
conn = db.connect('db')
cursor = conn.cursor()
conn.row_factory = db.Row
cursor.execute("select tc.cid, tc.title, tc.created, tc.text, "
"(select a.name "
"from typecho_metas a join typecho_relationships r on a.mid = r.mid "
"where r.cid = tc.cid and a.type ='category' "
"group by r.mid) as category "
"from typecho_contents tc "
"where tc.type = 'post'")
rows = cursor.fetchall()
for row in rows:
cid = row[0]
title = row[1]
data = row[2]
text = row[3]
categories = row[4]
tags = ""
template(title, categories, data, tags, text)
def template(title, categories, data, tags,text):
time_local = time.localtime(data)
dt = time.strftime("%Y-%m-%d %H:%M:%S", time_local)
template = "---\n" \
"title: %s\n" \
"categories: %s\n" \
"date: %s\n" \
"tags: %s\n" \
"---\n" %(title, categories, dt, tags)
template.decode()
f = file(title.replace(" ","-").replace("-"","-").replace(""","") + ".md", "a+")
f.write(template)
f.write(text.replace("<!--markdown-->",""))
f.close()
if __name__ == '__main__':
scan()

0%