]> git.scottworley.com Git - paperdoorknob/blob - paperdoorknob.py
b5b7a44a433f2410d64fb12c021348fac25171b8
[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{booktabs}
22 \\usepackage{graphicx}
23 \\usepackage{longtable}
24 \\usepackage{varwidth}
25 \\usepackage{wrapstuff}
26 ''')
27 if spec.geometry is not None:
28 spec.texout.write(b'\\usepackage[' +
29 spec.geometry.encode('UTF-8') +
30 b']{geometry}\n')
31 spec.texout.write(b'\\begin{document}\n')
32 url = flatURL(spec.url)
33 html = parse(spec.htmlfilter(spec.fetcher.fetch(url)))
34 for r in chunkDOMs(html):
35 spec.domfilter(r)
36 chunk = makeChunk(r, spec.images)
37 spec.texout.write(spec.layout.renderChunk(chunk))
38 spec.texout.write(b'\\end{document}\n')
39
40
41 def main() -> None:
42 with spec_from_commandline_args() as spec:
43 process(spec)
44
45
46 if __name__ == '__main__':
47 main()