]>
git.scottworley.com Git - paperdoorknob/blob - paperdoorknob.py
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
10 from bs4
import BeautifulSoup
13 from xdg_base_dirs
import xdg_cache_home
16 def command_line_parser() -> ArgumentParser
:
17 parser
= ArgumentParser(prog
='paperdoorknob', description
='Print glowfic')
21 help='Where to keep the http cache (instead of %(default)s)',
22 default
=os
.path
.join(xdg_cache_home(), "paperdoorknob"))
25 help='How long to wait for HTTP requests, in seconds',
27 parser
.add_argument('url', help='URL to retrieve')
31 def fetch(url
: str, session
: requests
.Session
, timeout
: int) -> BeautifulSoup
:
32 with session
.get(url
, timeout
=timeout
) as r
:
34 return BeautifulSoup(r
.text
, 'html.parser')
38 args
= command_line_parser().parse_args()
39 with requests_cache
.CachedSession(args
.cache_path
, cache_control
=True) as session
:
40 fetch(args
.url
, session
, args
.timeout
)
43 if __name__
== '__main__':