From 3e3442620b3798e86b02f5acc216a886f84e00d9 Mon Sep 17 00:00:00 2001 From: Phil Date: Thu, 20 Nov 2025 15:37:58 +0000 Subject: [PATCH] =?UTF-8?q?All=20feed=20entries=20processed=20instead=20of?= =?UTF-8?q?=20only=20the=20first.=20Sorted=20by=20published=20timestamp=20?= =?UTF-8?q?(oldest=20first)=20to=20maintain=20correct=20chronological=20or?= =?UTF-8?q?der=20in=20Discord.=20PEW=20colour=20rules=20still=20apply=20(O?= =?UTF-8?q?pen/Planned=20=E2=86=92=200x51D3D4).=20State=20saved=20per=20in?= =?UTF-8?q?cident=20so=20only=20updates/new=20incidents=20are=20posted.=20?= =?UTF-8?q?One=20post=20per=20incident=20=E2=80=94=20the=20latest=20update?= =?UTF-8?q?=20for=20an=20incident=20is=20posted.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aastatus_to_webhook.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/aastatus_to_webhook.py b/aastatus_to_webhook.py index 7af97fb..3b0b7da 100644 --- a/aastatus_to_webhook.py +++ b/aastatus_to_webhook.py @@ -55,7 +55,7 @@ def fetch_feed(url): def parse_feed_entries(feed_xml): - """Return a list of all valid entries in the feed.""" + """Return a list of all valid entries in the feed, sorted oldest first.""" entries = [] try: root = ET.fromstring(feed_xml) @@ -123,7 +123,7 @@ def parse_feed_entries(feed_xml): try: return datetime.fromisoformat(entry["published"].replace("Z", "+00:00")) except Exception: - return datetime.min # fallback if parsing fails + return datetime.min entries.sort(key=parse_date) return entries @@ -144,7 +144,7 @@ def html_to_markdown(html_content): return md.strip()[:3500] -### COLOR LOGIC (table-driven) ### +### COLOR LOGIC ### def get_event_color(status, severity): SPECIAL_COLORS = { @@ -222,10 +222,14 @@ def main(): state = load_state() + # Group entries by incident ID: latest entry wins + incidents = {} for entry in entries: - incident_id = entry["id"] - prev = state.get(incident_id) + incidents[entry["id"]] = entry # overwrite with latest entry for each incident + # Post updates per incident + for incident_id, entry in incidents.items(): + prev = state.get(incident_id) must_post = False change_type = "New entry" @@ -251,7 +255,7 @@ def main(): payload = build_discord_payload(entry, change_type) post_to_discord(WEBHOOK_URL, payload) - # Save state + # Save latest state state[incident_id] = { "status": entry["status"], "severity": entry["severity"],