From 4e352e01fb23d7f69f5f652dde59c938413d870b Mon Sep 17 00:00:00 2001 From: Phil Date: Thu, 20 Nov 2025 15:18:39 +0000 Subject: [PATCH] Added table-driven colour logic, Added PEW+Open and PEW+Planned colour to 0x51D3D4, Cleaned and refactor of "get_event_color()" --- aastatus_to_webhook.py | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/aastatus_to_webhook.py b/aastatus_to_webhook.py index 79506c5..23248f1 100644 --- a/aastatus_to_webhook.py +++ b/aastatus_to_webhook.py @@ -17,12 +17,13 @@ FEED_URL = "https://aastatus.net/atom.cgi" WEBHOOK_URL = "https://discord.com/api/webhooks/XXXXXXX" # Discord webhook URL STATE_FILE = Path("/tmp/aaisp_atom_state.json") -# Event colors +# Event colors (default fallbacks) COLOR_MINOR_OPEN = 0xFFFF00 # yellow COLOR_MAJOR_OPEN = 0xFF0000 # red COLOR_CLOSED = 0x2ECC71 # green COLOR_UNKNOWN = 0x95A5A6 # grey + ### STATE MANAGEMENT ### def load_state(): @@ -133,16 +134,36 @@ def html_to_markdown(html_content): return md.strip()[:3500] -### COLOR LOGIC ### +### COLOR LOGIC (refactored, table-driven) ### def get_event_color(status, severity): + """ + Determines the Discord embed colour based on status & severity. + Uses a lookup table for clarity and easy extensions. + """ + + # Special case colours for Planned Maintenance (PEW) + SPECIAL_COLORS = { + ("PEW", "Open"): 0x51D3D4, + ("PEW", "Planned"): 0x51D3D4, + } + + # Direct match first + key = (severity, status) + if key in SPECIAL_COLORS: + return SPECIAL_COLORS[key] + + # Normal rules if status == "Closed": return COLOR_CLOSED - if status == "Open" and severity == "Minor": - return COLOR_MINOR_OPEN - if status == "Open" and severity in ("Major", "MSO", "PEW"): - return COLOR_MAJOR_OPEN - return COLOR_UNKNOWN + + STATUS_SEVERITY_COLORS = { + ("Open", "Minor"): COLOR_MINOR_OPEN, + ("Open", "Major"): COLOR_MAJOR_OPEN, + ("Open", "MSO"): COLOR_MAJOR_OPEN, + } + + return STATUS_SEVERITY_COLORS.get((status, severity), COLOR_UNKNOWN) ### DISCORD FORMAT ### @@ -216,7 +237,7 @@ def main(): change_type = f"Status changed: {prev.get('status')} → {entry['status']}" elif entry["severity"] != prev.get("severity"): must_post = True - change_type = f"Severity changed: {prev.get('severity')} → {entry['severity']}" + change_type = f"Severity changed: {prev.get('severity']} → {entry['severity']}" elif entry["updated"] != prev.get("updated"): must_post = True change_type = "Feed updated" @@ -241,3 +262,4 @@ def main(): if __name__ == "__main__": main() +