]>
git.scottworley.com Git - paperdoorknob/blob - args.py
fb36083b28b9bcf852d37963f8b53c33760819d3
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.
8 from argparse
import ArgumentParser
9 from contextlib
import contextmanager
12 from typing
import Iterator
14 from xdg_base_dirs
import xdg_cache_home
16 from domfilter
import ApplyDOMFilters
, DOMFilters
17 from fetch
import CachingFetcher
18 from htmlfilter
import ApplyHTMLFilters
, HTMLFilters
20 from texify
import PandocTexifier
23 def _command_line_parser() -> ArgumentParser
:
24 parser
= ArgumentParser(prog
='paperdoorknob', description
='Print glowfic')
28 help='Where to keep the http cache (instead of %(default)s)',
29 default
=os
.path
.join(xdg_cache_home(), "paperdoorknob"))
32 help='Which DOM filters to use (default: %(default)s)',
33 default
=','.join(f
[0] for f
in DOMFilters
))
36 help='Which HTML filters to use (default: %(default)s)',
37 default
=','.join(f
[0] for f
in HTMLFilters
))
40 help='The filename stem at which to write output ' +
41 '(eg: "%(default)s" produces %(default)s.tex, %(default)s.pdf, etc.)',
43 parser
.add_argument('--pandoc', help='Location of the pandoc executable')
46 help='How long to wait for HTTP requests, in seconds',
50 help='URL to retrieve (example: https://www.projectlawful.com/posts/4582 )')
55 def spec_from_commandline_args() -> Iterator
[Spec
]:
56 args
= _command_line_parser().parse_args()
57 with CachingFetcher(args
.cache_path
, args
.timeout
) as fetcher
:
58 with open(args
.out
+ '.tex', 'wb') as texout
:
62 lambda x
: ApplyHTMLFilters(args
.htmlfilters
, x
),
63 lambda x
: ApplyDOMFilters(args
.domfilters
, x
),
64 PandocTexifier(args
.pandoc
or 'pandoc'),