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