# -*- coding: utf-8 -*- import pandas as pd import os import errno from sqlalchemy import * import sys reload(sys) sys.setdefaultencoding('utf8')
# Change me to the phriction database engine = create_engine( 'mysql://user:[email protected]/phabricator_phriction?charset=utf8mb4')
df=pd.read_sql('select * from phriction_content',engine)
defget(x): x=x.iloc[0] strpath='data/' + x['slug'][:-1] + '.md' #print strpath strdir = os.path.dirname(strpath) #print strdir try: os.makedirs(strdir) except OSError as exc: if exc.errno == errno.EEXIST and os.path.isdir(strdir): pass else: raise
withopen(strpath, 'w') as fp: fp.write(x['content'])
for name,group in df.groupby('title'): iflen(group) > 1: x=group[group['version'] == group['version'].max()] #Get only the latest version get(x) else: get(group)
NOTE: 这里有个小 bug:如果当某个页面 A 被 move 成 B 之后呢,这个程序只能 dump 出 A.md,而且里面是空的。