add verbosity option, update README
This commit is contained in:
parent
969a8778aa
commit
18327df580
2 changed files with 31 additions and 7 deletions
15
README.md
15
README.md
|
@ -21,11 +21,13 @@ python exporter.py \
|
|||
-f pdf,md,plaintext,html \
|
||||
-l pages,chapters,books
|
||||
-t ./token.txt \
|
||||
-V debug \
|
||||
-p ./
|
||||
```
|
||||
|
||||
Customization:
|
||||
```text
|
||||
options:
|
||||
-p PATH, --path PATH Path where exported files will be placed.
|
||||
Default: .
|
||||
-t TOKEN_FILE, --token-file TOKEN_FILE
|
||||
|
@ -34,17 +36,22 @@ Customization:
|
|||
-H HOST, --host HOST Your domain with protocol prefix, example: https://example.com
|
||||
Default: https://localhost
|
||||
-f FORMATS, --formats FORMATS
|
||||
Coma separated list of formats to use for export. Available ones: md,plaintext,pdf,html
|
||||
Default: md
|
||||
Coma separated list of formats to use for export.
|
||||
Available ones: markdown,plaintext,pdf,html
|
||||
default: markdown
|
||||
-l LEVEL, --level LEVEL
|
||||
Coma separated list of levels at which should be export performed.
|
||||
Available levels: ['pages', 'chapters', 'books']
|
||||
Default: pages
|
||||
-V LOG_LEVEL, --log-level LOG_LEVEL
|
||||
Set verbosity level.
|
||||
Available levels: dict_keys(['debug', 'info', 'warning', 'error'])
|
||||
Default: info
|
||||
|
||||
```
|
||||
|
||||
### TODO:
|
||||
- choosing verbosity level through command line parameter
|
||||
- ~~choosing verbosity level through command line parameter~~ Done
|
||||
- ~~choosing on what level should the notes be exported (Books, Chapters, Pages)~~ Done
|
||||
- (optional) choosing if update note file only if the last edit timestamp from API is later that the local file timestamp
|
||||
- WIP: choosing if update note file only if the last edit timestamp from API is later that the local file timestamp
|
||||
- suggestions?
|
||||
|
|
23
exporter.py
23
exporter.py
|
@ -7,8 +7,6 @@ from logging import info, error, debug
|
|||
from pathlib import Path
|
||||
from urllib.request import urlopen, Request
|
||||
|
||||
logging.basicConfig(format='%(levelname)s :: %(message)s', level=logging.DEBUG)
|
||||
|
||||
# (formatName, fileExtension)
|
||||
FORMATS: dict['str', 'str'] = {
|
||||
'markdown': 'md',
|
||||
|
@ -23,6 +21,13 @@ LEVELS = [
|
|||
'books'
|
||||
]
|
||||
|
||||
LOG_LEVEL: dict = {
|
||||
'debug': logging.DEBUG,
|
||||
'info': logging.INFO,
|
||||
'warning': logging.WARNING,
|
||||
'error': logging.ERROR
|
||||
}
|
||||
|
||||
parser = argparse.ArgumentParser(description='BookStack exporter')
|
||||
parser.add_argument('-p', '--path', type=str, default='.',
|
||||
help='Path where exported files will be placed.')
|
||||
|
@ -30,14 +35,24 @@ parser.add_argument('-t', '--token-file', type=str, default=f'.{os.path.sep}toke
|
|||
help='File containing authorization token in format TOKEN_ID:TOKEN_SECRET')
|
||||
parser.add_argument('-H', '--host', type=str, default='https://localhost',
|
||||
help='Your domain with protocol prefix, example: https://example.com')
|
||||
parser.add_argument('-f', '--formats', type=str, default='md',
|
||||
parser.add_argument('-f', '--formats', type=str, default='markdown',
|
||||
help=f'Coma separated list of formats to use for export.'
|
||||
f' Available ones: {",".join([f for f in FORMATS.keys()])}')
|
||||
parser.add_argument('-l', '--level', type=str, default='pages',
|
||||
help=f'Coma separated list of levels at which should be export performed. '
|
||||
f'Available levels: {LEVELS}')
|
||||
parser.add_argument('-V', '--log-level', type=str, default='info',
|
||||
help=f'Set verbosity level. '
|
||||
f'Available levels: {LOG_LEVEL.keys()}')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.log_level not in LOG_LEVEL.keys():
|
||||
error(f"Bad log level {args.log_level}, available levels: {LOG_LEVEL.keys()}")
|
||||
exit(1)
|
||||
|
||||
logging.basicConfig(format='%(levelname)s :: %(message)s', level=LOG_LEVEL.get(args.log_level))
|
||||
|
||||
formats = args.formats.split(',')
|
||||
for frmt in formats:
|
||||
if frmt not in FORMATS.keys():
|
||||
|
@ -116,6 +131,8 @@ def api_get_dict(path: str) -> dict:
|
|||
|
||||
|
||||
def check_if_update_needed(file: str, remote_last_edit: datetime) -> bool:
|
||||
if not os.path.exists(file):
|
||||
return True
|
||||
local_last_edit: datetime = datetime.fromtimestamp(os.path.getmtime(file))
|
||||
debug(f"Local file creation timestamp: {local_last_edit.date()} {local_last_edit.time()}, "
|
||||
f"remote edit timestamp: {remote_last_edit.date()} {remote_last_edit.time()}")
|
||||
|
|
Loading…
Reference in a new issue