This repository was archived by the owner on Apr 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbookstack.py
executable file
·66 lines (60 loc) · 2.26 KB
/
bookstack.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
#!/usr/bin/env python3
# An API Wrapper Library for boostack.
# Copyright 2022 GNU Public License v2
import subprocess,json,urllib.parse
class bookstack_api(object):
tokenid=""
tokensecret=""
bookstack_host=""
protocol="https"
port=80
def __init__(self,myhost="localhost",mytokenid="",mytokensecret=""):
self.tokenid=mytokenid
self.tokensecret=mytokensecret
self.bookstack_host=myhost
def set_token(self,mytokenid,mytokensecret):
self.tokenid=mytokenid
self.tokensecret=mytokensecret
def get_token(self):
return self.token+":"+self.tokensecret
def set_bookstack_host(self,myhost):
self.bookstack_host=myhost
def get_bookstack_host(self):
return self.bookstack_host
def set_protocol(self,myprotocol):
self.protocol=myprotocol
def get_protocol(self):
return self.protocol
def set_port(self,myport):
self.port=myport
def get_port(self):
return self.port
def call_get_api(self,apicall):
return json.loads((subprocess.getoutput("curl -sk --request GET --url "+self.protocol+"://"+self.bookstack_host+":"+str(self.port)+"/api/"+apicall+" --header 'Authorization: Token "+self.tokenid+":"+self.tokensecret+"'")))
def call_post_api(self,apicall,parameters):
curlcommand="curl -sk --request POST --url '"+self.protocol+"://"+self.bookstack_host+":"+str(self.port)+"/api/"+apicall+"?"
for param in parameters:
#print(param)
curlcommand=curlcommand+urllib.parse.quote(param)+"="+urllib.parse.quote(parameters[param])+"&"
curlcommand=curlcommand.rstrip("&")+"'"
curlcommand=curlcommand+" --header 'Authorization: Token "+self.tokenid+":"+self.tokensecret+"'"
#print(curlcommand)
x=subprocess.getoutput(curlcommand)
#print(x)
try:
return json.loads(x)
except:
return "Too big"
def call_put_api(self,apicall,parameters):
curlcommand="curl -sk --request PUT --url '"+self.protocol+"://"+self.bookstack_host+":"+str(self.port)+"/api/"+apicall+"?"
for param in parameters:
curlcommand=curlcommand+urllib.parse.quote(param)+"="+urllib.parse.quote(parameters[param])+"&"
curlcommand=curlcommand.rstrip("&")+"'"
curlcommand=curlcommand+" --header 'Authorization: Token "+self.tokenid+":"+self.tokensecret+"'"
#print(curlcommand)
x=subprocess.getoutput(curlcommand)
#print(x)
try:
return json.loads(x)
except:
return "Too big"