This repository has been archived by the owner on Oct 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wiki2storage.py
73 lines (57 loc) · 1.71 KB
/
wiki2storage.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
A quick script for running text through Confluence's conversion API end-point.
"""
import requests
import json
import time
import os
import sys
import argparse
hostname="wiki.ucl.ac.uk"
url = f"https://{hostname}/rest/api/contentbody/convert/"
with open("bearer.token") as f:
token = f.read()
headers = {
"Accept": "application/json",
"Authorization": 'Bearer '+ os.getenv("CONFLUENCE_PAC"),
#"Authorization": f"Bearer {token}",
"Accept": "application/json",
"Content-Type": "application/json"
}
def convert_format(page_text, f_from, f_to):
response = requests.request(
"POST",
url + f_to,
headers=headers,
json={"value": page_text, "representation": f_from} #{"value": page_text, "representation": "wiki"}
)
response.raise_for_status()
rj = response.json()
return rj
def w2s(page_text):
return convert_format(page_text, "wiki", "storage")["value"]
def s2v(page_text):
return convert_format(page_text, "storage", "view")["value"]
def w2v(page_text):
return s2v(w2s(page_text))
# Valid conversions:
# Source Representation Destination Representation Supported
# wiki storage
# storage view,export_view,styled_view,editor
# editor storage
# view None
# export_view None
# styled_view None
def main():
parser = argparse.ArgumentParser(
prog='wiki2storage',
description='Converts Confluence wiki format to storage format',
epilog='-')
parser.add_argument('filename', nargs="+")
args = parser.parse_args()
for filename in args.filename:
with open(filename, 'r') as f:
s = str(f.read())
print(w2v(s))
if __name__ == "__main__":
main()