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"],