]> git.scottworley.com Git - paperdoorknob/blame - paperdoorknob.py
fetch: Verify caching across sessions
[paperdoorknob] / paperdoorknob.py
CommitLineData
92b11a10
SW
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 argparse import ArgumentParser
b25a2f90 9import requests
b34a368f 10import requests_cache
92b11a10
SW
11
12
13def command_line_parser() -> ArgumentParser:
14 parser = ArgumentParser(prog='paperdoorknob', description='Print glowfic')
b25a2f90
SW
15 parser.add_argument(
16 '--timeout',
17 help='How long to wait for HTTP requests, in seconds',
18 default=30)
19 parser.add_argument('url', help='URL to retrieve')
92b11a10
SW
20 return parser
21
22
e138a9b4
SW
23def fetch(url: str, session: requests.Session, timeout: int) -> None:
24 with session.get(url, timeout=timeout) as r:
25 r.raise_for_status()
b25a2f90
SW
26
27
92b11a10 28def main() -> None:
b25a2f90 29 args = command_line_parser().parse_args()
b34a368f 30 with requests_cache.CachedSession() as session:
e138a9b4 31 fetch(args.url, session, args.timeout)
92b11a10
SW
32
33
34if __name__ == '__main__':
35 main()