How to dump all wiki pages from Phabricator

How to dump all wiki pages from Phabricator

参照的源代码在这里:https://gist.github.com/HackToHell/9f261728f4ceda1605c9b3b1f46addbc

install software

1
2
3
4
yum -y install \
python-sqlalchemy \
python-pandas \
MySQL-python;

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
27
28
29
30
31
32
33
34
35
36
37
38
# -*- 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)

def get(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

with open(strpath, 'w') as fp:
fp.write(x['content'])

for name,group in df.groupby('title'):
if len(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,而且里面是空的。