chore(dev): lint monitor.py and update flake dependencies

- Refactor `hosts/desktop/monitor.py` to resolve PEP8 violations (line lengths, trailing whitespace, blank line structure).
- Update `flake.lock` to incorporate the latest upstream changes for `antigravity`, `DankMaterialShell`, and `home-manager`.
This commit is contained in:
kiskaadee committed 2026-06-25 17:09:18 -05:00
1 parent 81c05c8122
commit ea9dfffcec
2 files changed
+23 -24

No files matched your search

Generated
+9 -9
View File
@@ -8,11 +8,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1782288772, "lastModified": 1782375110,
"narHash": "sha256-cLZ/6ZCuX5kyU/g/ppmGYGC5SYDQnwEcBCg934bU0Mo=", "narHash": "sha256-VgQr+Y1b3C9bCn68DVyrzJiLvF14Cxpcf66HV6MNkVM=",
"owner": "jacopone", "owner": "jacopone",
"repo": "antigravity-nix", "repo": "antigravity-nix",
"rev": "9339da3b94d8691a92e101e7be45f83ea5012f69", "rev": "738d61a4b7d88473adedda7b5dbc7b6bc5704020",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -49,11 +49,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1782274482, "lastModified": 1782412048,
"narHash": "sha256-QzEtKa5ROX8cNYDymcjB6oTfRBpEApGQ7PFsF85Gl5s=", "narHash": "sha256-iLCNbmbH1ltOrqBUf8ccN0DaPkFr8JrnwnEtoy1grog=",
"owner": "AvengeMedia", "owner": "AvengeMedia",
"repo": "DankMaterialShell", "repo": "DankMaterialShell",
"rev": "1a39b7f66ca2b8df23a546fe312619e05c61a13c", "rev": "016527fda910f21b36c079051def38b12c6d0aab",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -103,11 +103,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1782233665, "lastModified": 1782423922,
"narHash": "sha256-h/xOtrByoA/Ak1lWHn0O1lVZz4qWYbwOSLQ8YSwQO0I=", "narHash": "sha256-qPNd6lUohHP5gcJhqQ7rLV87RwIx0xYR2A4Frb9Zjc4=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "062581938b4a378a82dfbb294b494808157153a1", "rev": "5d320ab301cfaaca7d32514f13815d19d109f5f4",
"type": "github" "type": "github"
}, },
"original": { "original": {
+14 -15
View File
@@ -1,13 +1,13 @@
""" """
Dynu DDNS Smart IP Change Monitor and Updater. Dynu DDNS Smart IP Change Monitor and Updater.
This script determines the current public IPv4 address by querying multiple external This script determines the current public IPv4 address by querying multiple
resolvers sequentially. It compares the discovered IP against the last recorded external resolvers sequentially. It compares the discovered IP against the last
successful IP in a local history log. If a change is detected, it triggers the recorded successful IP in a local history log. If a change is detected, it
`ddclient.service` on-demand to perform the DNS record update. triggers the `ddclient.service` on-demand to perform the DNS record update.
This local-first state verification prevents making redundant API requests to the This local-first state verification prevents making redundant API requests to
DNS provider, avoiding potential rate-limiting, IP bans, or API abuse flags. the DNS provider, avoiding rate-limiting, IP bans, or API abuse flags.
""" """
import urllib.request import urllib.request
@@ -22,7 +22,7 @@ from datetime import datetime
# Defaults to a state directory managed securely by the systemd service unit. # Defaults to a state directory managed securely by the systemd service unit.
HISTORY_FILE = os.environ.get("HISTORY_FILE", "/var/lib/dynu/ip_history.jsonl") HISTORY_FILE = os.environ.get("HISTORY_FILE", "/var/lib/dynu/ip_history.jsonl")
# Fallback sequence of external reflection services to discover the public WAN IP. # Fallback sequence of external services to discover the public WAN IP.
PROVIDERS = [ PROVIDERS = [
"https://api.ipify.org", "https://api.ipify.org",
"https://ifconfig.me/ip", "https://ifconfig.me/ip",
@@ -35,8 +35,8 @@ def is_valid_public_ipv4(ip):
""" """
Validates that a string is a properly formatted public IPv4 address. Validates that a string is a properly formatted public IPv4 address.
This function excludes standard private, loopback, link-local, and CGNAT blocks This function excludes standard private, loopback, link-local, and CGNAT
to avoid recording temporary, local, or invalid network states. blocks to avoid recording temporary, local, or invalid network states.
""" """
match = re.match(r"^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$", ip) match = re.match(r"^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$", ip)
if not match: if not match:
@@ -71,7 +71,7 @@ def is_valid_public_ipv4(ip):
def get_public_ip(): def get_public_ip():
""" """
Queries public IP providers sequentially until a valid public IPv4 is returned. Queries public IP providers until a valid public IPv4 is returned.
Returns: Returns:
str: The validated public IP string, or None if all providers fail. str: The validated public IP string, or None if all providers fail.
@@ -85,7 +85,7 @@ def get_public_ip():
'User-Agent': 'Mozilla/5.0 (NixOS WAN Monitor)' 'User-Agent': 'Mozilla/5.0 (NixOS WAN Monitor)'
} }
) )
# Fetch content with a strict 5 second timeout to prevent hanging the systemd task # Fetch with 5s timeout to avoid hanging the systemd service
with urllib.request.urlopen(req, timeout=5) as response: with urllib.request.urlopen(req, timeout=5) as response:
ip = response.read().decode('utf-8').strip() ip = response.read().decode('utf-8').strip()
if is_valid_public_ipv4(ip): if is_valid_public_ipv4(ip):
@@ -104,7 +104,7 @@ def get_public_ip():
def get_last_recorded_ip(): def get_last_recorded_ip():
""" """
Reads the history log from the bottom up to locate the last successful IP address. Reads the history log to locate the last successful IP address.
Returns: Returns:
str: The last successfully updated IP, or None if no log exists yet. str: The last successfully updated IP, or None if no log exists yet.
@@ -156,7 +156,7 @@ def trigger_ddclient():
tuple: (bool, str) representing (success_boolean, error_details_string) tuple: (bool, str) representing (success_boolean, error_details_string)
""" """
try: try:
# Run ddclient as a one-shot activation via systemd to perform the API call # Run ddclient as a one-shot activation via systemd to perform API call
res = subprocess.run( res = subprocess.run(
["systemctl", "start", "ddclient.service"], ["systemctl", "start", "ddclient.service"],
capture_output=True, capture_output=True,
@@ -184,7 +184,7 @@ def main():
last_ip = get_last_recorded_ip() last_ip = get_last_recorded_ip()
if current_ip == last_ip: if current_ip == last_ip:
# IP matches the last recorded working IP; do nothing to conserve API quota # IP matches last recorded working IP; do nothing to conserve quota
sys.exit(0) sys.exit(0)
print(f"IP rotation detected! Old: {last_ip}, New: {current_ip}") print(f"IP rotation detected! Old: {last_ip}, New: {current_ip}")
@@ -203,4 +203,3 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() main()