jkjk not final

This commit is contained in:
olari
2021-05-28 04:13:27 +03:00
parent 0e1fd8b4a9
commit 3aef7c4133
7 changed files with 308 additions and 98 deletions

24
extract_toc.py Normal file
View File

@@ -0,0 +1,24 @@
from subprocess import run
import sys
outline = run(
['mutool', 'show', sys.argv[1], 'outline'],
capture_output=True
).stdout.decode('utf-8')
indent = 0
last_quote_index = 0
for line in outline.splitlines():
quote_index = line.find('"')
hash_index = line.find('#')
if quote_index > last_quote_index:
indent += 1
elif quote_index < last_quote_index:
indent -= 1
last_quote_index = quote_index
title = line[quote_index+1:line.find('"', quote_index+1)].strip()
page = int(line[hash_index+1:line.find(',', hash_index+1)])
print(f'{"#"*indent} {title} ({page})')