simple2-http-checking 1.0.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.
@@ -0,0 +1,36 @@
1
+ Metadata-Version: 2.4
2
+ Name: simple2-http-checking
3
+ Version: 1.0.0
4
+ Summary: A simple CLI tool to check the status of URLs.
5
+ Description-Content-Type: text/markdown
6
+ License-File: LICENSE
7
+ Requires-Dist: requests<3.0,>=2.28
8
+ Requires-Dist: click<9.0,>=8.0
9
+ Provides-Extra: dev
10
+ Requires-Dist: pytest; extra == "dev"
11
+ Requires-Dist: pytest-mock; extra == "dev"
12
+ Requires-Dist: ruff; extra == "dev"
13
+ Requires-Dist: black; extra == "dev"
14
+ Requires-Dist: mypy; extra == "dev"
15
+ Requires-Dist: bandit; extra == "dev"
16
+ Requires-Dist: types-requests; extra == "dev"
17
+ Dynamic: license-file
18
+
19
+ # Python Projects: CI/CD
20
+ This repo contains the code for the CI/CD sections of my Python for Devops course.
21
+
22
+ ## What we implement in this repository
23
+
24
+ [] Implement the project (code files)
25
+
26
+ [] Add a simple GHA workflow and make sure it runs until completion
27
+
28
+ [] Add linting (ruff) and format checks (black)
29
+
30
+ [] Add typing (mypy) and security checks (bandit)
31
+
32
+ [] Add test automation
33
+
34
+ [] Build our Python project
35
+
36
+ [] Publish the project to both TestPyPi and Pypi when a new release is published
@@ -0,0 +1,9 @@
1
+ simple2_http_checking-1.0.0.dist-info/licenses/LICENSE,sha256=QvAcMQD05Dp7l3pP767QXQlGAoA6Ks0qgoEvubzdQpo,1073
2
+ simple_http_checker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ simple_http_checker/checker.py,sha256=daH0PK0yU-rqQSb1Sp110mrOgZXniFW7wjknD-Pkx2Q,1587
4
+ simple_http_checker/cli.py,sha256=pVsCBgTdd0kHRs-DOmHX6IB9-vt-zuMP84oFutD9QWc,1641
5
+ simple2_http_checking-1.0.0.dist-info/METADATA,sha256=RabsksuB00JFoO7b_XsurG-dDKEKNlAsUPBdf9blkLk,1059
6
+ simple2_http_checking-1.0.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
7
+ simple2_http_checking-1.0.0.dist-info/entry_points.txt,sha256=UF_7hQD8GGstiCxqZgH6XC6YbiUxh7ZDf5o8Wg0NhDE,60
8
+ simple2_http_checking-1.0.0.dist-info/top_level.txt,sha256=Q2N-cYyXd23OQxUK_TdugtDVBHGsKaM2V2JOF5ygKtk,20
9
+ simple2_http_checking-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ check-urls = simple_http_checker.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ABDELAZIZ MTIMET
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ simple_http_checker
File without changes
@@ -0,0 +1,54 @@
1
+ import logging
2
+
3
+ import requests
4
+
5
+ logger = logging.getLogger(__name__)
6
+
7
+
8
+ def check_urls(
9
+ urls: list[str], timeout: int = 5
10
+ ) -> dict[str, str]:
11
+ """
12
+ Check the status of a list of URLs.
13
+
14
+ Args:
15
+ urls: A list of URLs to check.
16
+ timeout: The timeout for each HTTP request, in seconds.
17
+
18
+ Returns:
19
+ A dictionary mapping each URL to its status
20
+ (an HTTP status code, or a short error description).
21
+ """
22
+ logger.info(
23
+ f"Checking {len(urls)} URLs with a timeout of {timeout} seconds."
24
+ )
25
+ results: dict[str, str] = {}
26
+
27
+ for url in urls:
28
+ try:
29
+ logger.debug(f"Checking URL: {url}")
30
+ response = requests.get(url, timeout=timeout)
31
+
32
+ if response.ok:
33
+ status = str(response.status_code)
34
+ else:
35
+ status = (
36
+ f"{response.status_code} - {response.reason}"
37
+ )
38
+ except requests.exceptions.Timeout:
39
+ status = "TIMEOUT"
40
+ logger.warning(f"Timeout occurred for URL: {url}")
41
+ except requests.exceptions.ConnectionError:
42
+ status = "CONNECTION ERROR"
43
+ logger.warning(
44
+ f"Connection error occurred for URL: {url}"
45
+ )
46
+ except requests.exceptions.RequestException as e:
47
+ status = f"ERROR - {type(e).__name__}"
48
+ logger.exception(f"Request exception for URL: {url}")
49
+
50
+ results[url] = status
51
+ logger.debug(f"Checked: {url:<40} Status: {status}")
52
+
53
+ logger.info("URL checking completed.")
54
+ return results
@@ -0,0 +1,63 @@
1
+ import logging
2
+ import sys
3
+ from _collections_abc import Collection
4
+
5
+ import click
6
+
7
+ from simple_http_checker.checker import check_urls
8
+
9
+ logger = logging.getLogger(__name__)
10
+
11
+
12
+ @click.command(
13
+ name="check_urls",
14
+ help="Check the status of one or more URLs.",
15
+ )
16
+ @click.argument("urls", nargs=-1, required=True)
17
+ @click.option(
18
+ "--timeout",
19
+ type=click.IntRange(min=1),
20
+ default=5,
21
+ show_default=True,
22
+ help="Timeout for each request, in seconds.",
23
+ )
24
+ @click.option(
25
+ "--verbose",
26
+ "-v",
27
+ is_flag=True,
28
+ help="Show detailed debug logs.",
29
+ )
30
+ def main(urls: Collection[str], timeout: int, verbose: bool):
31
+ """Check the status of one or more URLs."""
32
+ logging.basicConfig(
33
+ level=logging.DEBUG if verbose else logging.WARNING,
34
+ format="%(levelname)s:%(name)s:%(message)s",
35
+ force=True,
36
+ )
37
+ if verbose:
38
+ logging.getLogger().setLevel(logging.DEBUG)
39
+ logger.debug("Verbose mode enabled.")
40
+ logger.debug(f"Received urls: {urls}")
41
+ logger.debug(f"Received timeout: {timeout} seconds")
42
+ logger.debug(f"Received verbose flag: {verbose}")
43
+ if not urls:
44
+ logger.error("No URLs provided.")
45
+ click.echo("Error: No URLs provided.", err=True)
46
+ sys.exit(1)
47
+ results = check_urls(list(urls), timeout=timeout)
48
+
49
+ failed = 0
50
+ for url, status in results.items():
51
+ ok = status.isdigit()
52
+ if not ok:
53
+ failed += 1
54
+ click.secho(
55
+ f"{url:<40} {status}", fg="green" if ok else "red"
56
+ )
57
+
58
+ click.echo(
59
+ f"\n{len(results) - failed}/{len(results)} URLs OK"
60
+ )
61
+
62
+ if failed:
63
+ sys.exit(1)