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:
parent
574cecb8c1
commit
3e3442620b
@ -55,7 +55,7 @@ def fetch_feed(url):
|
|||||||
|
|
||||||
|
|
||||||
def parse_feed_entries(feed_xml):
|
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 = []
|
entries = []
|
||||||
try:
|
try:
|
||||||
root = ET.fromstring(feed_xml)
|
root = ET.fromstring(feed_xml)
|
||||||
@ -123,7 +123,7 @@ def parse_feed_entries(feed_xml):
|
|||||||
try:
|
try:
|
||||||
return datetime.fromisoformat(entry["published"].replace("Z", "+00:00"))
|
return datetime.fromisoformat(entry["published"].replace("Z", "+00:00"))
|
||||||
except Exception:
|
except Exception:
|
||||||
return datetime.min # fallback if parsing fails
|
return datetime.min
|
||||||
|
|
||||||
entries.sort(key=parse_date)
|
entries.sort(key=parse_date)
|
||||||
return entries
|
return entries
|
||||||
@ -144,7 +144,7 @@ def html_to_markdown(html_content):
|
|||||||
return md.strip()[:3500]
|
return md.strip()[:3500]
|
||||||
|
|
||||||
|
|
||||||
### COLOR LOGIC (table-driven) ###
|
### COLOR LOGIC ###
|
||||||
|
|
||||||
def get_event_color(status, severity):
|
def get_event_color(status, severity):
|
||||||
SPECIAL_COLORS = {
|
SPECIAL_COLORS = {
|
||||||
@ -222,10 +222,14 @@ def main():
|
|||||||
|
|
||||||
state = load_state()
|
state = load_state()
|
||||||
|
|
||||||
|
# Group entries by incident ID: latest entry wins
|
||||||
|
incidents = {}
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
incident_id = entry["id"]
|
incidents[entry["id"]] = entry # overwrite with latest entry for each incident
|
||||||
prev = state.get(incident_id)
|
|
||||||
|
|
||||||
|
# Post updates per incident
|
||||||
|
for incident_id, entry in incidents.items():
|
||||||
|
prev = state.get(incident_id)
|
||||||
must_post = False
|
must_post = False
|
||||||
change_type = "New entry"
|
change_type = "New entry"
|
||||||
|
|
||||||
@ -251,7 +255,7 @@ def main():
|
|||||||
payload = build_discord_payload(entry, change_type)
|
payload = build_discord_payload(entry, change_type)
|
||||||
post_to_discord(WEBHOOK_URL, payload)
|
post_to_discord(WEBHOOK_URL, payload)
|
||||||
|
|
||||||
# Save state
|
# Save latest state
|
||||||
state[incident_id] = {
|
state[incident_id] = {
|
||||||
"status": entry["status"],
|
"status": entry["status"],
|
||||||
"severity": entry["severity"],
|
"severity": entry["severity"],
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user