Adiciona linting config e body JSON no ping

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Ronaldo Dias 2026-06-07 03:01:14 -03:00
parent 9f79f1a8b5
commit bc5c03118f
3 changed files with 37 additions and 3 deletions

8
.shellcheckrc Normal file
View file

@ -0,0 +1,8 @@
# shellcheck configuration
shell=bash
enable=all
severity=warning
# SC2312: Ignore "consider invoking separately to avoid masking return values"
# (common pattern with command -v in this project)
disable=SC2312

View file

@ -1,11 +1,14 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import json
import os import os
import sys import sys
import urllib.request
import urllib.error import urllib.error
import urllib.request
from datetime import datetime, timezone from datetime import datetime, timezone
from pathlib import Path from pathlib import Path
PAYLOAD = json.dumps({"name": "Ronaldo Freitas Dias"}).encode()
def load_url_from_config(): def load_url_from_config():
config_file = Path.home() / ".config" / "health-monitor" config_file = Path.home() / ".config" / "health-monitor"
@ -16,8 +19,11 @@ def load_url_from_config():
return None return None
HEADERS = {"User-Agent": "health-monitor/1.0", "Content-Type": "application/json"}
def ping(url: str, timeout: int) -> int: def ping(url: str, timeout: int) -> int:
req = urllib.request.Request(url, method="GET", headers={"User-Agent": "health-monitor/1.0"}) req = urllib.request.Request(url, data=PAYLOAD, method="GET", headers=HEADERS)
with urllib.request.urlopen(req, timeout=timeout) as response: with urllib.request.urlopen(req, timeout=timeout) as response:
return response.getcode() return response.getcode()
@ -25,7 +31,7 @@ def ping(url: str, timeout: int) -> int:
def ping_fail(url: str, timeout: int) -> None: def ping_fail(url: str, timeout: int) -> None:
fail_url = url.rstrip("/") + "/fail" fail_url = url.rstrip("/") + "/fail"
try: try:
req = urllib.request.Request(fail_url, method="GET", headers={"User-Agent": "health-monitor/1.0"}) req = urllib.request.Request(fail_url, data=PAYLOAD, method="GET", headers=HEADERS)
urllib.request.urlopen(req, timeout=timeout) urllib.request.urlopen(req, timeout=timeout)
except Exception: except Exception:
pass pass

20
pyproject.toml Normal file
View file

@ -0,0 +1,20 @@
[tool.ruff]
target-version = "py39"
line-length = 110
[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"UP", # pyupgrade
"B", # flake8-bugbear
"SIM", # flake8-simplify
]
ignore = [
"B904", # raise from exc — não obrigatório em scripts simples
]
[tool.ruff.lint.isort]
known-first-party = ["healthcheck"]