]> git.scottworley.com Git - paperdoorknob/blame_incremental - paperdoorknob.py
More structure and tests around splitting the page into chunks' DOMs.
[paperdoorknob] / paperdoorknob.py
... / ...
CommitLineData
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
8from bs4 import BeautifulSoup
9
10from args import spec_from_commandline_args
11from glowfic import chunkDOMs
12from spec import Spec
13
14
15def parse(content: bytes) -> BeautifulSoup:
16 return BeautifulSoup(content, 'html.parser')
17
18
19def process(spec: Spec) -> None:
20 spec.texout.write(b'\\documentclass{article}\n')
21 if spec.geometry is not None:
22 spec.texout.write(b'\\usepackage[' +
23 spec.geometry.encode('UTF-8') +
24 b']{geometry}\n')
25 spec.texout.write(b'\\begin{document}\n')
26 html = parse(spec.htmlfilter(spec.fetcher.fetch(spec.url)))
27 for r in chunkDOMs(html):
28 spec.domfilter(r)
29 spec.texout.write(spec.texifier.texify(r))
30 spec.texout.write(b'\\end{document}\n')
31
32
33def main() -> None:
34 with spec_from_commandline_args() as spec:
35 process(spec)
36
37
38if __name__ == '__main__':
39 main()