BookStack-Python-exporter/README.md

103 lines
5.4 KiB
Markdown
Raw Permalink Normal View History

2022-05-13 18:14:52 +00:00
# BookStack-Python-exporter
Customizable script for exporting notes from BookStack through API
2022-05-13 18:44:05 +00:00
2022-05-13 19:12:38 +00:00
#### Features:
2023-12-31 15:20:27 +00:00
- export keeping the tree structure by making folders from Shelves, Books, Chapters and attachments (including attachments from external links)
2022-05-13 19:12:38 +00:00
- export multiple formats at once
2022-06-22 14:03:40 +00:00
- export at multiple levels at once (export Books or/and Chapters or/and Pages as files)
2022-07-27 09:56:39 +00:00
- choose if local files should be updated only if their edit timestamp is older than remote document last edit, or timestamps should be ignored and files will always be overwritten with the newest version
2022-05-13 19:12:38 +00:00
- customizable path for placing exported notes
- configure replacing any characters in filenames with "_" for any filesystem compatibility
2022-05-13 19:12:38 +00:00
- authorization token is loaded from txt file
- Set custom HTTP User-Agent header to bypass filtering based on that header (like in CloudFlare tunnels)
- Set arbitrary custom headers through parameter
2022-05-13 19:12:38 +00:00
Requirements:
- Python at least in version 3.6
2022-05-13 18:44:05 +00:00
Full example on how to use the script:
1. Clone the repo
2. next to the script place token.txt file containing token id and token secret in format: TOKEN_ID:TOKEN_SECRET
3. in the same directory run the command, specifying your app domain with https prefix (every parameter is optional as it have default value, this is an example):
2022-05-13 18:44:05 +00:00
```bash
2022-06-22 14:03:40 +00:00
python exporter.py \
-H https://wiki.example.com \
2022-07-27 10:02:06 +00:00
-f pdf markdown plaintext html \
-l pages chapters books \
--rate-limit 180 \
-c "/" "#" \
--force-update-files \
2022-06-22 14:03:40 +00:00
-t ./token.txt \
2022-06-23 11:50:06 +00:00
-V debug \
-p ./ \
--user-agent "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/112.0"
--additional-headers "Header1: value1" "Header2: value2"
2022-05-13 18:44:05 +00:00
```
Customization:
```text
2023-12-31 15:20:27 +00:00
usage: exporter.py [-h] [-p PATH] [-t TOKEN_FILE] [-H HOST]
[-f {markdown,plaintext,pdf,html} [{markdown,plaintext,pdf,html} ...]]
[--rate-limit RATE_LIMIT]
2023-12-31 15:20:27 +00:00
[-c FORBIDDEN_CHARS [FORBIDDEN_CHARS ...]] [-u USER_AGENT]
[--additional-headers ADDITIONAL_HEADERS [ADDITIONAL_HEADERS ...]]
[-l {pages,chapters,books} [{pages,chapters,books} ...]]
[--force-update-files] [--dont-export-attachments]
[--dont-export-external-attachments]
[-V {debug,info,warning,error}]
2023-12-31 15:20:27 +00:00
BookStack exporter
optional arguments:
-h, --help show this help message and exit
2022-05-13 18:44:05 +00:00
-p PATH, --path PATH Path where exported files will be placed.
-t TOKEN_FILE, --token-file TOKEN_FILE
File containing authorization token in format
TOKEN_ID:TOKEN_SECRET
-H HOST, --host HOST Your domain with protocol prefix, example:
https://example.com
2023-12-31 15:20:27 +00:00
-f {markdown,plaintext,pdf,html} [{markdown,plaintext,pdf,html} ...], --formats {markdown,plaintext,pdf,html} [{markdown,plaintext,pdf,html} ...]
Space separated list of formats to use for export.
--rate-limit RATE_LIMIT
How many api requests can be made in a minute. Default
is 180 (BookStack defaults)
-c FORBIDDEN_CHARS [FORBIDDEN_CHARS ...], --forbidden-chars FORBIDDEN_CHARS [FORBIDDEN_CHARS ...]
Space separated list of symbols to be replaced with
"_" in filenames.
-u USER_AGENT, --user-agent USER_AGENT
User agent header content. In situations where
requests are blocked because of bad
client/unrecognized web browser/etc (like with
CloudFlare tunnels), change to some typical web
browser user agent header.
--additional-headers ADDITIONAL_HEADERS [ADDITIONAL_HEADERS ...]
List of arbitrary additional HTTP headers to be sent
with every HTTP request. They can override default
ones, including Authorization header. IMPORTANT: these
headers are also sent when downloading external
attachments! Don't put here any private data.Example:
-u "Header1: value1" "Header2: value2"
2023-12-31 15:20:27 +00:00
-l {pages,chapters,books} [{pages,chapters,books} ...], --level {pages,chapters,books} [{pages,chapters,books} ...]
Space separated list of levels at which should be
export performed.
--force-update-files Set this option to skip checking local files
timestamps against remote last edit timestamps. This
will cause overwriting local files, even if they seem
to be already in newest version.
2023-12-31 15:20:27 +00:00
--dont-export-attachments
Set this to prevent exporting any attachments.
2023-12-31 15:20:27 +00:00
--dont-export-external-attachments
Set this to prevent exporting external attachments
(from links).
-V {debug,info,warning,error}, --log-level {debug,info,warning,error}
Set verbosity level.
2022-05-13 18:44:05 +00:00
```
### TODO:
2022-07-27 09:56:39 +00:00
- [x] ~~choosing verbosity level through command line parameter~~ Done
- [x] ~~choosing on what level should the notes be exported (Books, Chapters, Pages)~~ Done
- [x] ~~choosing if update note file only if the last edit timestamp from API is later that the local file timestamp~~ Done
2023-12-31 15:20:27 +00:00
- [x] ~~exporting attachments~~
- [x] ~~api rate limiting~~
2022-07-27 09:56:39 +00:00
- [ ] suggestions?