97 lines
2.3 KiB
Python
97 lines
2.3 KiB
Python
"""Data models for the browser monitoring application."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
from datetime import datetime
|
|
from typing import Any, Optional
|
|
|
|
|
|
@dataclass
|
|
class PageSnapshot:
|
|
"""Structured representation of a captured page state."""
|
|
|
|
website_id: str
|
|
website_name: str
|
|
requested_url: str
|
|
final_url: str
|
|
timestamp: datetime
|
|
title: str
|
|
visible_text: str
|
|
html: str
|
|
screenshot_path: Optional[str]
|
|
load_duration: float
|
|
success: bool
|
|
error: Optional[str] = None
|
|
|
|
|
|
@dataclass
|
|
class ProcessingResult:
|
|
"""Result from OpenAI processing (or stub)."""
|
|
|
|
success: bool
|
|
value: Optional[Any] = None
|
|
condition_met: bool = False
|
|
message: str = ""
|
|
email_subject: str = ""
|
|
email_body: str = ""
|
|
reason: str = ""
|
|
|
|
|
|
@dataclass
|
|
class WebsiteConfig:
|
|
"""Configuration for a single monitored website."""
|
|
|
|
id: str
|
|
name: str
|
|
url: str
|
|
enabled: bool = True
|
|
extra: dict[str, Any] = field(default_factory=dict)
|
|
|
|
|
|
@dataclass
|
|
class BrowserConfig:
|
|
"""Browser automation settings."""
|
|
|
|
type: str = "chrome"
|
|
executable_path: Optional[str] = None
|
|
headless: bool = False
|
|
profile_directory: str = "./profiles/default"
|
|
|
|
|
|
@dataclass
|
|
class MonitorConfig:
|
|
"""Monitoring loop settings."""
|
|
|
|
round_robin_delay_seconds: float = 5.0
|
|
page_load_timeout_seconds: float = 30.0
|
|
render_wait_seconds: float = 3.0
|
|
snapshot_directory: str = "./snapshots"
|
|
snapshot_retention_count: int = 50
|
|
browser_restart_max_retries: int = 3
|
|
browser_restart_backoff_seconds: float = 5.0
|
|
|
|
|
|
@dataclass
|
|
class NotificationChannelConfig:
|
|
"""Per-channel notification settings."""
|
|
|
|
enabled: bool = False
|
|
|
|
|
|
@dataclass
|
|
class NotificationsConfig:
|
|
"""Notification settings."""
|
|
|
|
sms: NotificationChannelConfig = field(default_factory=NotificationChannelConfig)
|
|
email: NotificationChannelConfig = field(default_factory=NotificationChannelConfig)
|
|
|
|
|
|
@dataclass
|
|
class AppConfig:
|
|
"""Root application configuration."""
|
|
|
|
browser: BrowserConfig = field(default_factory=BrowserConfig)
|
|
monitor: MonitorConfig = field(default_factory=MonitorConfig)
|
|
websites: list[WebsiteConfig] = field(default_factory=list)
|
|
notifications: NotificationsConfig = field(default_factory=NotificationsConfig)
|