http-checker 1.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1,57 @@
1
+ import logging
2
+ import requests
3
+ from typing import Collection
4
+
5
+ logger = logging.getLogger(__name__)
6
+
7
+
8
+ def check_urls(
9
+ urls: Collection[str], timeout: int = 5
10
+ ) -> dict[str, str]:
11
+ """
12
+ Checks a list of URLs and returns their status.
13
+
14
+ Args:
15
+ urls: A list of URL strings to check.
16
+ timeout: Maximum time in seconds to wait for each request. Defaults to 5.
17
+
18
+ Returns:
19
+ A dictionary mapping each URL to its status string.
20
+ """
21
+
22
+ logger.info(
23
+ f"Starting check for {len(urls)} URLs with a timeout of {timeout}"
24
+ )
25
+ results: dict[str, str] = {}
26
+
27
+ for url in urls:
28
+ status = "UNKNOWN"
29
+
30
+ try:
31
+ logger.debug(f"Checking URL: {url}")
32
+ response = requests.get(url, timeout=timeout)
33
+
34
+ if response.ok:
35
+ status = f"{response.status_code} OK"
36
+ else:
37
+ status = (
38
+ f"{response.status_code} {response.reason}"
39
+ )
40
+ except requests.exceptions.Timeout:
41
+ status = "TIMEOUT"
42
+ logger.warning(f"Request to {url} timed out.")
43
+ except requests.exceptions.ConnectionError:
44
+ status = "CONNECTION_ERROR"
45
+ logger.warning(f"Connection error for {url}.")
46
+ except requests.exceptions.RequestException as e:
47
+ status = f"REQUEST_ERROR: {type(e).__name__}"
48
+ logger.error(
49
+ f"An unexpected request error occured for {url}: {e}",
50
+ exc_info=True,
51
+ )
52
+
53
+ results[url] = status
54
+ logger.debug(f"Checked: {url:<40} -> {status}")
55
+
56
+ logger.info("URL check finished.")
57
+ return results
http_checker/cli.py ADDED
@@ -0,0 +1,54 @@
1
+ import logging
2
+ import click
3
+ from .checker import check_urls
4
+ from typing import Collection
5
+
6
+ logging.basicConfig(
7
+ level=logging.INFO,
8
+ format="[%(asctime)s] %(levelname)-8s %(name)s: %(message)s",
9
+ datefmt="%Y-%m-%d %H:%M:%S",
10
+ )
11
+
12
+ logger = logging.getLogger(__name__)
13
+
14
+
15
+ @click.command()
16
+ @click.argument("urls", nargs=-1)
17
+ @click.option(
18
+ "--timeout",
19
+ default=5,
20
+ help="Timeout for each URL check in seconds.",
21
+ )
22
+ @click.option(
23
+ "--verbose",
24
+ "-v",
25
+ is_flag=True,
26
+ help="Enable verbose logging.",
27
+ )
28
+ def main(urls: Collection[str], timeout: int, verbose: bool):
29
+
30
+ if verbose:
31
+ logging.getLogger().setLevel(logging.DEBUG)
32
+ logger.debug("Verbose logging enabled.")
33
+
34
+ logger.debug(f"Received urls: {urls}")
35
+ logger.debug(f"Received timeout: {timeout}")
36
+ logger.debug(f"Received verbose flag: {verbose}")
37
+
38
+ if not urls:
39
+ logger.warning(
40
+ "No URLs provided. Please provide at least one URL to check."
41
+ )
42
+ click.echo("Usage: check-urls <URL1> <URL2> ...")
43
+ return
44
+
45
+ logger.info(f"Starting check for {len(urls)} URLs.")
46
+ results = check_urls(urls, timeout)
47
+
48
+ click.echo("\n --- Results ----")
49
+ for url, status in results.items():
50
+ if "OK" in status:
51
+ fg_color = "green"
52
+ else:
53
+ fg_color = "red"
54
+ click.secho(f"{url:<40} -> {status}", fg=fg_color)
@@ -0,0 +1,28 @@
1
+ Metadata-Version: 2.4
2
+ Name: http-checker
3
+ Version: 1.5.0
4
+ Summary: A simple CLI tool to check the status of URLs.
5
+ Requires-Python: >=3.9
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: requests<3.0,>=2.28
9
+ Requires-Dist: click<9.0,>=8.0
10
+ Provides-Extra: dev
11
+ Requires-Dist: pytest; extra == "dev"
12
+ Requires-Dist: pytest-mock; extra == "dev"
13
+ Requires-Dist: ruff; extra == "dev"
14
+ Requires-Dist: black; extra == "dev"
15
+ Requires-Dist: mypy; extra == "dev"
16
+ Requires-Dist: bandit; extra == "dev"
17
+ Requires-Dist: types-requests; extra == "dev"
18
+ Dynamic: license-file
19
+
20
+ ## Implementaion
21
+
22
+ [x] Project files (code files)
23
+ [x] Add simple GHA workflow and make sure it runs completion
24
+ [x] Add linting (ruff) and format checks (black)
25
+ [] Add typing and security checks
26
+ [] Add test automation
27
+ [] Build our Python project
28
+ [] Publish the project to bet TestPyPi and PyPi when a new tag is pushed
@@ -0,0 +1,9 @@
1
+ http_checker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ http_checker/checker.py,sha256=T9J20gUFSuss-T6MfFO_8LD6jGAxOE4Q9jiE0ZAHuIc,1664
3
+ http_checker/cli.py,sha256=WjYsXVReNO77IWqyuBdrCN32icSyUMtTwWAblbTTONc,1389
4
+ http_checker-1.5.0.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ http_checker-1.5.0.dist-info/METADATA,sha256=pPaCriXrkzD7LYhRRSIuR_9C424RSvbmoG6AdoEPFJM,897
6
+ http_checker-1.5.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
7
+ http_checker-1.5.0.dist-info/entry_points.txt,sha256=qlCEGCd28UEdZVS_9DlBhJnXRfLDcauT4kkhYv41Kek,53
8
+ http_checker-1.5.0.dist-info/top_level.txt,sha256=p_A8BMdCxxgJ3tG4OKL8MuB9hqcCHliOFczcX7LPTLg,13
9
+ http_checker-1.5.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ check-urls = http_checker.cli:main
File without changes
@@ -0,0 +1 @@
1
+ http_checker