Add API_URL support + POST reporting logic

This commit is contained in:
serversdwn
2025-11-20 18:24:57 -05:00
parent de3b46a09e
commit a03d4a1f05

View File

@@ -28,6 +28,7 @@ import csv
import time import time
import configparser import configparser
import urllib.request import urllib.request
import requests
from datetime import datetime, timezone, timedelta from datetime import datetime, timezone, timedelta
from typing import Dict, Any, Optional, Tuple, Set, List from typing import Dict, Any, Optional, Tuple, Set, List
@@ -273,6 +274,21 @@ def refresh_roster_from_url(url: str, dest: str, min_seconds: int,
def cfg_get(cfg: dict, key: str, default=None): def cfg_get(cfg: dict, key: str, default=None):
return cfg.get(key, cfg.get(key.lower(), cfg.get(key.upper(), default))) return cfg.get(key, cfg.get(key.lower(), cfg.get(key.upper(), default)))
#---Report to server ---
def report_to_server(server_url: str, uid: str, info: dict, status: str):
payload = {
"unit": uid,
"unit_type": "series3",
"timestamp": fmt_last(info["mtime"]),
"file": info["fname"],
"status": status
}
try:
requests.post(server_url, json=payload, timeout=5)
except Exception as e:
print(f"[WARN] report_to_server failed for {uid}: {e}")
# --------------- Main loop ------------------ # --------------- Main loop ------------------
def main() -> None: def main() -> None:
here = os.path.dirname(__file__) or "." here = os.path.dirname(__file__) or "."
@@ -408,6 +424,8 @@ def main() -> None:
line = "{col}{uid:<8} Missing Age: N/A Last: ---{note}{rst}".format(col=C_MIS, uid=uid, note=note_suffix, rst=C_RST) line = "{col}{uid:<8} Missing Age: N/A Last: ---{note}{rst}".format(col=C_MIS, uid=uid, note=note_suffix, rst=C_RST)
print(line) print(line)
log_message(LOG_FILE, ENABLE_LOGGING, line) log_message(LOG_FILE, ENABLE_LOGGING, line)
if info is not None:
report_to_server(cfg["API_URL"], uid, info, status)
# Bench Units (rostered but not active in field) # Bench Units (rostered but not active in field)
print("\nBench Units (rostered, not active):") print("\nBench Units (rostered, not active):")