Add files via upload

This commit is contained in:
David Leutgeb 2020-07-14 16:58:46 +02:00 committed by GitHub
parent de3dd13c37
commit c1851f0960
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 0 deletions

49
exportBooks.py Normal file
View 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
View File

@ -0,0 +1,5 @@
certifi==2020.6.20
chardet==3.0.4
idna==2.10
requests==2.24.0
urllib3==1.25.9