From 31747c4bd317684c809174b0659c0724db596c17 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Wed, 13 May 2026 15:34:41 -0400 Subject: [PATCH] Replace deprecated datetime.utcnow() with datetime.now(timezone.utc) datetime.utcnow() is deprecated in Python 3.12 and removed in 3.13. Replace all four call sites with timezone-aware equivalents so the codebase is ready for Python 3.12+. Co-Authored-By: Claude Sonnet 4.6 --- db.py | 4 ++-- monitor.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/db.py b/db.py index 3e60cd2..7760154 100644 --- a/db.py +++ b/db.py @@ -3,7 +3,7 @@ import json import logging import threading from contextlib import contextmanager -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from typing import Optional import pymysql @@ -281,7 +281,7 @@ def create_suppression( ) -> int: expires_at = None if expires_minutes: - expires_at = datetime.utcnow() + timedelta(minutes=int(expires_minutes)) + expires_at = datetime.now(timezone.utc) + timedelta(minutes=int(expires_minutes)) with get_conn() as conn: with conn.cursor() as cur: cur.execute( diff --git a/monitor.py b/monitor.py index 8a928a9..f872999 100644 --- a/monitor.py +++ b/monitor.py @@ -12,7 +12,7 @@ import logging import re import shlex import time -from datetime import datetime +from datetime import datetime, timezone from typing import Dict, List, Optional import requests @@ -618,7 +618,7 @@ class LinkStatsCollector: return { 'hosts': result_hosts, 'unifi_switches': unifi_switches, - 'updated': datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC'), + 'updated': datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S UTC'), } def _compute_unifi_rates(self, raw: Dict[str, dict], now: float) -> Dict[str, dict]: @@ -653,7 +653,7 @@ class LinkStatsCollector: # Helpers # -------------------------------------------------------------------------- def _now_utc() -> str: - return datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC') + return datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S UTC') # -------------------------------------------------------------------------- @@ -921,7 +921,7 @@ class NetworkMonitor: return { 'hosts': hosts, 'unifi': display_unifi, - 'updated': datetime.utcnow().isoformat() + 'Z', + 'updated': datetime.now(timezone.utc).isoformat().replace('+00:00', 'Z'), } # ------------------------------------------------------------------