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