39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
if str(ROOT) not in sys.path:
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from src.api.alerts import get_alert_silent_window_status
|
|
|
|
|
|
def main(env=None) -> int:
|
|
env = os.environ if env is None else env
|
|
output_json = _get_bool(env, "ALERT_SILENT_WINDOW_OUTPUT_JSON", False)
|
|
payload = get_alert_silent_window_status()
|
|
if output_json:
|
|
print(json.dumps(payload, ensure_ascii=False, sort_keys=True, default=str))
|
|
else:
|
|
print(f"Alert silent window: {'active' if payload.get('active') else 'inactive'}")
|
|
print(f"Window: {payload.get('window_label')}")
|
|
print(f"Timezone: {payload.get('timezone')}")
|
|
if payload.get("next_allowed_ts"):
|
|
print(f"Next allowed: {payload.get('next_allowed_ts')}")
|
|
return 0
|
|
|
|
|
|
def _get_bool(env, key: str, default: bool = False) -> bool:
|
|
value = env.get(key)
|
|
if value is None or value == "":
|
|
return default
|
|
return str(value).strip().lower() in {"1", "true", "yes", "on"}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|