]> git.scottworley.com Git - paperdoorknob/blame_incremental - paperdoorknob.py
fetch: test: Choose port dynamically
[paperdoorknob] / paperdoorknob.py
... / ...
CommitLineData
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
9import requests
10
11
12def command_line_parser() -> ArgumentParser:
13 parser = ArgumentParser(prog='paperdoorknob', description='Print glowfic')
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')
19 return parser
20
21
22def fetch(url: str, timeout: int) -> None:
23 r = requests.get(url, timeout=timeout)
24 r.raise_for_status()
25
26
27def main() -> None:
28 args = command_line_parser().parse_args()
29 fetch(args.url, args.timeout)
30
31
32if __name__ == '__main__':
33 main()