simple-http-checker-d-superteach 1.2.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,53 @@
1
+ import logging
2
+ from collections.abc import Collection
3
+
4
+ import requests
5
+
6
+ logger = logging.getLogger(__name__)
7
+
8
+ # Uncomment line below to showcase workflow fail -> security check error from bandit
9
+ # API_TOKEN = "ghp_ThisLooksLikeAPersonalGitHubAccessToken"
10
+
11
+
12
+ def check_urls(urls: Collection[str], timeout: int = 5) -> dict[str, str]:
13
+ """
14
+ Checks a list of URLs and returns their status.
15
+
16
+ Args:
17
+ urls: A list of URLs to check.
18
+ timeout: Maximum time in seconds to wait for each request. Defaults to 5.
19
+
20
+ Return:
21
+ A dictionary mapping each URL to its status string.
22
+ """
23
+
24
+ logger.info(f"Starting check for {len(urls)} URLs with a timeout of {timeout} s.")
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 = f"{response.status_code} {response.reason}"
38
+
39
+ except requests.exceptions.Timeout:
40
+ status = "TIMEOUT"
41
+ logger.warning(f"Request to {url} timed out.")
42
+ except requests.exceptions.ConnectionError:
43
+ status = "CONNECTION_ERROR"
44
+ logger.warning(f"Connection error for {url}")
45
+ except requests.exceptions.RequestException as e:
46
+ status = f"REQUEST_ERROR: {type(e).__name__}"
47
+ # logger.error(f"An unexpected request error occured for {url}: {e}", exc_info=True)
48
+ logger.exception(f"An unexpected request error occured for {url}")
49
+ results[url] = status
50
+ logger.debug(f"Checked {url:<40} -> {status}")
51
+
52
+ logger.info("URL check finished.")
53
+ return results
@@ -0,0 +1,50 @@
1
+ import logging
2
+ from collections.abc import Collection
3
+
4
+ import click
5
+
6
+ from .checker import check_urls
7
+
8
+ logging.basicConfig(
9
+ level=logging.INFO,
10
+ format="[%(asctime)s] %(levelname)-8s %(name)s: %(message)s",
11
+ datefmt="%Y-%m-%d %H:%M:%S",
12
+ )
13
+
14
+ logger = logging.getLogger(__name__)
15
+
16
+
17
+ @click.command()
18
+ @click.argument("urls", nargs=-1)
19
+ @click.option("--timeout", "-t", default=5, help="Timeout in seconds for each request.")
20
+ @click.option("--verbose", "-v", is_flag=True, help="Enable debug logging.")
21
+ def main(urls: Collection[str], timeout: int, verbose: bool):
22
+ if verbose:
23
+ logging.getLogger().setLevel(logging.DEBUG)
24
+ logger.debug("Verbose logging enabled.")
25
+
26
+ logger.debug(f"Received urls: {urls}")
27
+ logger.debug(f"Received timeout: {timeout}")
28
+ logger.debug(f"Received verbose: {verbose}")
29
+
30
+ if not urls:
31
+ logger.warning("No URLs provided to check.")
32
+ click.echo("Usage: check-urls <URL1> <URL2> ...")
33
+ return
34
+
35
+ logger.info(f"Starting check for {len(urls)} URLs.")
36
+
37
+ results = check_urls(urls, timeout=timeout)
38
+
39
+ click.echo("\n--- RESULTS ---")
40
+ for url, status in results.items():
41
+ if "OK" in status:
42
+ fg_color = "green"
43
+ else:
44
+ fg_color = "red"
45
+ click.secho(f"{url:<40} -> {status}", fg=fg_color)
46
+
47
+
48
+ # Example usage (in-terminal command)
49
+ # pip install -e .
50
+ # check-urls -vt10 https://www.google.com https://www.github.com https://www.aajdfhhjsdbgsjbndfjok.com http://httpbin.org/status/404
@@ -0,0 +1,31 @@
1
+ Metadata-Version: 2.4
2
+ Name: simple-http-checker-d-superteach
3
+ Version: 1.2.0
4
+ Summary: A simple CLI tool to check the status of URLs.
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: requests<3.0,>=2.34
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
+ Dynamic: license-file
18
+
19
+ # Python for DevOps: CI/CD for Python Projects
20
+
21
+ This repo contains the code for the CI/CD section of my Python for DevOps course.
22
+
23
+ ## What we implement in this project
24
+
25
+ - [x] Implement the project (code files)
26
+ - [x] Add a simple GHA workflow and make sure it runs until completion
27
+ - [x] Add lint (`ruff`) and format (`black`) checks
28
+ - [x] Add type (`mypy`) and security (`bandit`) checks
29
+ - [x] Add test automation
30
+ - [x] Build the project
31
+ - [ ] Publish the project to both `TestPyPI` and `PyPI` when a new tag is pushed
@@ -0,0 +1,9 @@
1
+ simple_http_checker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ simple_http_checker/checker.py,sha256=l4RC68AvC5Ho75-WDujgT4usvQTjf_MYK6w2sWP58L8,1787
3
+ simple_http_checker/cli.py,sha256=_5-gs9V70Z6CtiOaF7BH5fLPBT2G4W72sMHzfNf_8B8,1506
4
+ simple_http_checker_d_superteach-1.2.0.dist-info/licenses/LICENSE,sha256=oylYHUxyiLBg-N9AdyHUmY9y2VN5N6P-e9EkDcbA__0,1063
5
+ simple_http_checker_d_superteach-1.2.0.dist-info/METADATA,sha256=Y3HrFlIsft7_LIE8zJ5JQlLZ34QRclBa7FvxGGTH-Gs,1074
6
+ simple_http_checker_d_superteach-1.2.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
7
+ simple_http_checker_d_superteach-1.2.0.dist-info/entry_points.txt,sha256=UF_7hQD8GGstiCxqZgH6XC6YbiUxh7ZDf5o8Wg0NhDE,60
8
+ simple_http_checker_d_superteach-1.2.0.dist-info/top_level.txt,sha256=Q2N-cYyXd23OQxUK_TdugtDVBHGsKaM2V2JOF5ygKtk,20
9
+ simple_http_checker_d_superteach-1.2.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
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 mvpris
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