]> git.scottworley.com Git - paperdoorknob/blob - paperdoorknob.py
4ee4dbc2a0fca7208d62ec9fd8c6e212087c5062
[paperdoorknob] / paperdoorknob.py
1 # paperdoorknob: Print glowfic
2 #
3 # This program is free software: you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License as published by the
5 # Free Software Foundation, version 3.
6
7
8 from bs4 import BeautifulSoup
9
10 from args import spec_from_commandline_args
11 from glowfic import chunkDOMs, flatURL, makeChunk
12 from spec import Spec
13
14
15 def parse(content: bytes) -> BeautifulSoup:
16 return BeautifulSoup(content, 'html.parser')
17
18
19 def process(spec: Spec) -> None:
20 spec.texout.write(b'''\\documentclass{article}
21 \\usepackage{graphicx}
22 \\usepackage{varwidth}
23 \\usepackage{wrapstuff}
24 ''')
25 if spec.geometry is not None:
26 spec.texout.write(b'\\usepackage[' +
27 spec.geometry.encode('UTF-8') +
28 b']{geometry}\n')
29 spec.texout.write(b'\\begin{document}\n')
30 url = flatURL(spec.url)
31 html = parse(spec.htmlfilter(spec.fetcher.fetch(url)))
32 for r in chunkDOMs(html):
33 spec.domfilter(r)
34 chunk = makeChunk(r, spec.images)
35 spec.texout.write(spec.layout.renderChunk(chunk))
36 spec.texout.write(b'\\end{document}\n')
37
38
39 def main() -> None:
40 with spec_from_commandline_args() as spec:
41 process(spec)
42
43
44 if __name__ == '__main__':
45 main()