All feed entries processed instead of only the first. Sorted by published timestamp (oldest first) to maintain correct chronological order in Discord. PEW colour rules still apply (Open/Planned → 0x51D3D4). State saved per incident so only updates/new incidents are posted. One post per incident — the latest update for an incident is posted.

This commit is contained in:
Phil 2025-11-20 15:37:58 +00:00
parent 574cecb8c1
commit 3e3442620b

View File

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