Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -33,7 +33,7 @@ logging.basicConfig(
|
|
| 33 |
format='[%(asctime)s] %(levelname)s: %(message)s',
|
| 34 |
datefmt='%I:%M:%S %p',
|
| 35 |
handlers=[
|
| 36 |
-
logging.FileHandler("app.log"),
|
| 37 |
logging.StreamHandler()
|
| 38 |
]
|
| 39 |
)
|
|
@@ -279,6 +279,12 @@ def send_event_alerts(events):
|
|
| 279 |
<td style="padding: 8px 0;">{ev.get('location', '-')}</td>
|
| 280 |
</tr>
|
| 281 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
<tr>
|
| 283 |
<td style="padding: 8px 0; font-weight: bold;">Logger URL</td>
|
| 284 |
<td style="padding: 8px 0;">:</td>
|
|
@@ -473,9 +479,9 @@ def process_tick():
|
|
| 473 |
# Task 1: Load state if we just started
|
| 474 |
if LAST_EVENT_ID is None:
|
| 475 |
load_state()
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
if err:
|
| 480 |
logger.error(f"Error scraping events: {err}")
|
| 481 |
send_email_message(
|
|
@@ -489,6 +495,19 @@ def process_tick():
|
|
| 489 |
logger.error("Notifier is shutting down completely because of the scraping error.")
|
| 490 |
raise SystemExit(1)
|
| 491 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 492 |
if new_events:
|
| 493 |
# If LAST_EVENT_ID is None, it's the very first startup run. Set ID without alerting.
|
| 494 |
if LAST_EVENT_ID is None:
|
|
|
|
| 33 |
format='[%(asctime)s] %(levelname)s: %(message)s',
|
| 34 |
datefmt='%I:%M:%S %p',
|
| 35 |
handlers=[
|
| 36 |
+
logging.FileHandler("app.log", encoding="utf-8"),
|
| 37 |
logging.StreamHandler()
|
| 38 |
]
|
| 39 |
)
|
|
|
|
| 279 |
<td style="padding: 8px 0;">{ev.get('location', '-')}</td>
|
| 280 |
</tr>
|
| 281 |
|
| 282 |
+
<tr>
|
| 283 |
+
<td style="padding: 8px 0; font-weight: bold;">Status</td>
|
| 284 |
+
<td style="padding: 8px 0;">:</td>
|
| 285 |
+
<td style="padding: 8px 0;">{ev.get('status', '-')}</td>
|
| 286 |
+
</tr>
|
| 287 |
+
|
| 288 |
<tr>
|
| 289 |
<td style="padding: 8px 0; font-weight: bold;">Logger URL</td>
|
| 290 |
<td style="padding: 8px 0;">:</td>
|
|
|
|
| 479 |
# Task 1: Load state if we just started
|
| 480 |
if LAST_EVENT_ID is None:
|
| 481 |
load_state()
|
| 482 |
+
|
| 483 |
+
# FETCH ALL EVENTS FIRST (Safer architecture integration)
|
| 484 |
+
data, err = fetch_bip_events(xsrf, bip, page=1)
|
| 485 |
if err:
|
| 486 |
logger.error(f"Error scraping events: {err}")
|
| 487 |
send_email_message(
|
|
|
|
| 495 |
logger.error("Notifier is shutting down completely because of the scraping error.")
|
| 496 |
raise SystemExit(1)
|
| 497 |
|
| 498 |
+
resources = data.get("resources", [])
|
| 499 |
+
parsed_events = [parse_event(r) for r in resources] if resources else []
|
| 500 |
+
|
| 501 |
+
# 1. Track state changes for *all* fetched events (New Feature)
|
| 502 |
+
try:
|
| 503 |
+
from event_state_tracker import track_event_changes
|
| 504 |
+
track_event_changes(parsed_events)
|
| 505 |
+
except Exception as e:
|
| 506 |
+
logger.error(f"Event state tracker failed: {e}")
|
| 507 |
+
|
| 508 |
+
# 2. Check for entirely new events (Existing Logic)
|
| 509 |
+
new_events, _ = check_new_events(LAST_EVENT_ID, xsrf, bip)
|
| 510 |
+
|
| 511 |
if new_events:
|
| 512 |
# If LAST_EVENT_ID is None, it's the very first startup run. Set ID without alerting.
|
| 513 |
if LAST_EVENT_ID is None:
|