Added table-driven colour logic, Added PEW+Open and PEW+Planned colour to 0x51D3D4, Cleaned and refactor of "get_event_color()"

This commit is contained in:
Phil 2025-11-20 15:18:39 +00:00
parent 19bc33270e
commit 4e352e01fb

View File

@ -17,12 +17,13 @@ FEED_URL = "https://aastatus.net/atom.cgi"
WEBHOOK_URL = "https://discord.com/api/webhooks/XXXXXXX" # Discord webhook URL WEBHOOK_URL = "https://discord.com/api/webhooks/XXXXXXX" # Discord webhook URL
STATE_FILE = Path("/tmp/aaisp_atom_state.json") STATE_FILE = Path("/tmp/aaisp_atom_state.json")
# Event colors # Event colors (default fallbacks)
COLOR_MINOR_OPEN = 0xFFFF00 # yellow COLOR_MINOR_OPEN = 0xFFFF00 # yellow
COLOR_MAJOR_OPEN = 0xFF0000 # red COLOR_MAJOR_OPEN = 0xFF0000 # red
COLOR_CLOSED = 0x2ECC71 # green COLOR_CLOSED = 0x2ECC71 # green
COLOR_UNKNOWN = 0x95A5A6 # grey COLOR_UNKNOWN = 0x95A5A6 # grey
### STATE MANAGEMENT ### ### STATE MANAGEMENT ###
def load_state(): def load_state():
@ -133,16 +134,36 @@ def html_to_markdown(html_content):
return md.strip()[:3500] return md.strip()[:3500]
### COLOR LOGIC ### ### COLOR LOGIC (refactored, table-driven) ###
def get_event_color(status, severity): 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": if status == "Closed":
return COLOR_CLOSED return COLOR_CLOSED
if status == "Open" and severity == "Minor":
return COLOR_MINOR_OPEN STATUS_SEVERITY_COLORS = {
if status == "Open" and severity in ("Major", "MSO", "PEW"): ("Open", "Minor"): COLOR_MINOR_OPEN,
return COLOR_MAJOR_OPEN ("Open", "Major"): COLOR_MAJOR_OPEN,
return COLOR_UNKNOWN ("Open", "MSO"): COLOR_MAJOR_OPEN,
}
return STATUS_SEVERITY_COLORS.get((status, severity), COLOR_UNKNOWN)
### DISCORD FORMAT ### ### DISCORD FORMAT ###
@ -216,7 +237,7 @@ def main():
change_type = f"Status changed: {prev.get('status')}{entry['status']}" change_type = f"Status changed: {prev.get('status')}{entry['status']}"
elif entry["severity"] != prev.get("severity"): elif entry["severity"] != prev.get("severity"):
must_post = True 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"): elif entry["updated"] != prev.get("updated"):
must_post = True must_post = True
change_type = "Feed updated" change_type = "Feed updated"
@ -241,3 +262,4 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() main()