1 # paperdoorknob: Print glowfic
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.
10 from typing
import Iterable
12 from bs4
import BeautifulSoup
13 from bs4
.element
import Tag
15 from args
import spec_from_commandline_args
19 def parse(content
: bytes) -> BeautifulSoup
:
20 return BeautifulSoup(content
, 'html.parser')
23 def replies(html
: BeautifulSoup
) -> Iterable
[Tag
]:
27 text
= body
.find_next("div", class_
="post-post")
28 assert isinstance(text
, Tag
)
31 def the_replies() -> Iterable
[Tag
]:
32 rs
= html
.find_all("div", class_
="post-reply")
33 assert all(isinstance(r
, Tag
) for r
in rs
)
36 return itertools
.chain([text()], the_replies())
39 def process(spec
: Spec
) -> None:
40 spec
.texout
.write(b
'\\documentclass{article}\n')
41 if spec
.geometry
is not None:
42 spec
.texout
.write(b
'\\usepackage[' +
43 spec
.geometry
.encode('UTF-8') +
45 spec
.texout
.write(b
'\\begin{document}\n')
46 html
= parse(spec
.htmlfilter(spec
.fetcher
.fetch(spec
.url
)))
47 for r
in replies(html
):
49 spec
.texout
.write(spec
.texifier
.texify(r
))
50 spec
.texout
.write(b
'\\end{document}\n')
54 with spec_from_commandline_args() as spec
:
58 if __name__
== '__main__':