把博客从typecho转到了hugo,其实很早我就很喜欢用hugo,但是碍于一直没有好看的主题(留下了不懂设计的泪水),就一直没有采用,最近发现生态好了很多,就把之前打算切换到博客园的决定改为了切换到hugo,一篇篇搬运文章实在是太麻烦了,于是随手就写了个小工具。
第三方依赖只有pymysql,基本上改一下数据库配置就可以用了,用其他数据库的需要自己改造一下,对了,说明一下,时间戳转换的函数是网上找来的,谁写的没有记,侵删~
话不多说,Talk is cheap, show me the code!
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
|
import pymysql,time
import codecs
def timestamp_to_time(timeStamp):
timeArray = time.localtime(timeStamp)
otherStyleTime = time.strftime("%Y-%m-%d", timeArray)
return otherStyleTime
db = pymysql.connect(host='127.0.0.1',user='root',password='123456',database='blog')
cursor = db.cursor()
count = cursor.execute("select * from typecho_contents")
contents = cursor.fetchall()
for item in contents:
fp = codecs.open(item[1] + ".md","x","utf-8")
fp.write('---\n')
fp.write('title: ' + item[1] + '\n')
fp.write('date: ' + timestamp_to_time(item[3]) + '\n')
fp.write('draft: false\n')
fp.write('---\n')
fp.write(item[5])
fp.close()
db.close()
|
Gist:https://gist.github.com/devzhi/00a88f1cbe805452d53232050d6dc8fb