Developer

Language: English
Appearance

Theme

Accent colour

Your theme and colour carry over to satelit.md and the app.

Sign in

Where should the theme change?

Choose where the new theme applies.

You can change it any time from the header.

Cookbook · Python 3.9+

Daily war risk brief

Every 10 minutes Satelit recomputes, from the news, the probability of six scenarios for Moldova over the next 12 months. Each morning the script writes a brief with every scenario, its baseline and how far it moved since yesterday, and tells you only when it matters.

Runs on
Python 3.9+
One run
2 credits
A month
60 credits
Set up in
5 min
$ MOVE_PP=2 ABOVE=25 python3 war_brief.pywar-brief-2026-11-20.md: index 19.3%, 1 scenario moved, 2 credits

How it works

  1. Read the index and the six scenarios from /v1/war: the probability now, the baseline and whether it is a military escalation.
  2. Read the index's last 30 days from /v1/war/history?scenario=index.
  3. Compare with yesterday's brief in war-state.json and write war-brief-YYYY-MM-DD.md.
  4. Send an alert when a scenario moved MOVE_PP points or more, or when the index is above ABOVE percent.

What it costs: 1 credit for the scenarios and 1 for the history: 2 credits a day, 60 a month. Fits the Start plan.

How to run it

bash
export SATELIT_KEY=sat_live_...
MOVE_PP=2 ABOVE=25 python3 war_brief.py

What it outputs

stdout
war-brief-2026-11-20.md: index 19.3%, 1 scenario moved, 2 credits

The full script

war_brief.py
#!/usr/bin/env python3
"""War risk brief: Moldova's six war scenarios each morning, a Markdown brief and an alert when one moves.

    SATELIT_KEY=sat_live_... MOVE_PP=2 ABOVE=25 python3 war_brief.py

Writes war-brief-YYYY-MM-DD.md: the index and every scenario now, its baseline, its move since the last brief and the
index's last 30 days. Alerts (ALERT_URL, a Slack-style incoming webhook; empty prints them) when a scenario moved MOVE_PP
percentage points or more since the last brief, or when the index is above ABOVE percent. BRIEF_LANG: ro, ru, en or uk.
Standard library only. Put it in cron: 0 8 * * * python3 /path/war_brief.py
"""
import json
import os
import sys
import time
import urllib.error
import urllib.parse
import urllib.request
from datetime import date
from pathlib import Path

sys.stdout.reconfigure(encoding="utf-8")  # names hold ă, ș, ț whatever the console's code page

BASE = os.environ.get("SATELIT_BASE", "https://api.satelit.md/v1")
KEY = os.environ["SATELIT_KEY"]
LANG = os.environ.get("BRIEF_LANG", "ro")
MOVE_PP = float(os.environ.get("MOVE_PP", "2"))
ABOVE = float(os.environ.get("ABOVE", "25"))
ALERT_URL = os.environ.get("ALERT_URL", "")
STATE = Path(os.environ.get("STATE_FILE", "war-state.json"))
credits_used = 0


def api(path, **params):
    global credits_used
    query = urllib.parse.urlencode({"lang": LANG, **params})
    req = urllib.request.Request(f"{BASE}{path}?{query}", headers={"Authorization": f"Bearer {KEY}"})
    for attempt in range(3):
        try:
            with urllib.request.urlopen(req, timeout=20) as res:
                body = json.load(res)
                credits_used += body["meta"].get("credits", 0)
                return body["data"]
        except urllib.error.HTTPError as err:
            retry = err.headers.get("Retry-After")
            if err.code in (429, 503) and retry and attempt < 2:
                time.sleep(int(retry))
                continue
            raise SystemExit(f"{path}: {err.code} {err.read().decode()}")


def alert(text):
    print(text)
    if ALERT_URL:
        req = urllib.request.Request(ALERT_URL, json.dumps({"text": text}).encode(), {"Content-Type": "application/json"})
        urllib.request.urlopen(req, timeout=10).close()


def pct(p):
    return f"{p * 100:.1f}%"


def pp(x):
    return f"{x:+.1f} pp"


def main():
    now = api("/war")
    days = api("/war/history", scenario="index", days=30)
    rows = [now["index"], *now["scenarios"]]
    last = json.loads(STATE.read_text("utf-8")) if STATE.exists() else {}
    moved = []
    lines = [f"# War risk for Moldova, {date.today().isoformat()}", "",
             f"Probability over the next {now['horizon_months']} months. Change: since the last brief.", "",
             "| Scenario | Now | Baseline | Change |", "|---|---:|---:|---:|"]
    for r in rows:
        before = last.get(r["scenario"])
        change = (r["probability"] - before) * 100 if before is not None else 0.0
        if r["scenario"] != "index" and before is not None and abs(change) >= MOVE_PP:
            moved.append(f"{r['name']}: {pct(r['probability'])} ({pp(change)})")
        lines.append(f"| {r['name']} | {pct(r['probability'])} | {pct(r['prior'])} | {pp(change) if before is not None else 'new'} |")
    points = [d["probability"] for d in days]
    if points:
        lines += ["", f"Index, last {len(points)} days: from {pct(min(points))} to {pct(max(points))}, now {pct(points[-1])}."]
    lines += ["", "Estimates: Satelit (satelit.md). Not an official forecast."]
    out = Path(f"war-brief-{date.today().isoformat()}.md")
    out.write_text("\n".join(lines) + "\n", "utf-8")
    STATE.write_text(json.dumps({r["scenario"]: r["probability"] for r in rows}), "utf-8")

    index = now["index"]["probability"] * 100
    if moved:
        alert("War risk moved: " + "; ".join(moved) + ". Satelit's estimate.")
    if index > ABOVE:
        alert(f"War risk index at {index:.1f}%, above {ABOVE:g}%. Satelit's estimate.")
    print(f"{out}: index {pct(now['index']['probability'])}, {len(moved)} scenarios moved, {credits_used} credits")


if __name__ == "__main__":
    main()

Routes used

Data in this cookbook

Updated:

Questions about this cookbook

Where do the probabilities come from?

They are Satelit's estimates from the war news about Moldova and the region, recomputed every 10 minutes. They are not an official forecast and rest on no secret sources.

Can I see the stories that moved a scenario?

Yes, /v1/war/signals gives each story with the points it moved each scenario, on Pro and above. The war.news and war.risk webhooks are on every plan with webhooks.

Can I get the alert in real time, not in the morning?

Yes: the war.level webhook comes when a scenario crosses a line of yours, for example {"scenario": "transnistria", "above": 15}. This script is for the daily brief.