Add files via upload
This commit is contained in:
parent
de3dd13c37
commit
c1851f0960
49
exportBooks.py
Normal file
49
exportBooks.py
Normal file
@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
import json
|
||||
import os
|
||||
from datetime import date
|
||||
|
||||
# Change this vars as you need
|
||||
|
||||
bookstack_url = "https://wiki.yourbookstack.local" # Bookstack Base URL
|
||||
header = {'Authorization': 'Token xxxx:xxxx'} # API Token
|
||||
cert_verify_url = "/etc/ssl/certs/ca-certificates.crt" # Cert Store for verifying the SSL Cert
|
||||
export_path = "exports/" # Where the exported books will be saved
|
||||
|
||||
# Leave this vars UNCHANGED
|
||||
|
||||
books_url = "{}/api/books".format(bookstack_url)
|
||||
|
||||
# Get a list of books available on the Bookstack instance
|
||||
|
||||
books = requests.get(books_url, headers=header, verify=cert_verify_url)
|
||||
books_data = json.dumps(books.json(), separators=(',', ':'))
|
||||
books_data_loads = json.loads(books_data)
|
||||
books_data_data = books_data_loads['data']
|
||||
|
||||
# Create folder with the current date, if it already exists exit
|
||||
|
||||
folder_name = "{}/{}".format(export_path, date.today())
|
||||
|
||||
if not os.path.exists(folder_name):
|
||||
os.mkdir(folder_name)
|
||||
else:
|
||||
print("Folder already exists")
|
||||
exit()
|
||||
|
||||
|
||||
# For every book export it as html
|
||||
|
||||
for book in books_data_data:
|
||||
export_url = "{}/{}/export/html".format(books_url, book['id'])
|
||||
export_file_name = "{}/{}.html".format(folder_name, book['name'])
|
||||
|
||||
book_html = requests.get(export_url, headers=header, verify=cert_verify_url)
|
||||
with open(export_file_name, "w+") as file:
|
||||
file.write(book_html.text)
|
||||
|
||||
print("Successfully exported book {}".format(book['name']))
|
||||
|
||||
print("Export finished")
|
5
requirements.txt
Normal file
5
requirements.txt
Normal file
@ -0,0 +1,5 @@
|
||||
certifi==2020.6.20
|
||||
chardet==3.0.4
|
||||
idna==2.10
|
||||
requests==2.24.0
|
||||
urllib3==1.25.9
|
Loading…
Reference in New Issue
Block a user