Skip to content

Watch a sector

You will build: a job that runs every hour, reads the sector outlooks, and posts to a Slack (or any webhook) channel when a sector’s risk level changes or its direction turns to rising.

You need: a key with intel:read, and a webhook URL for your channel.

GET /outlooks returns one reading per sector your workspace follows:

{
"sector": "energy_power",
"name": "Energy and power",
"quiet": false,
"risk_score": 48,
"risk_level": "elevated",
"previous_score": 61,
"direction": "easing",
"verdict": "No new Hormuz attack or Tarali ruling emerged in the last 24 hours; …",
"drivers": [
{ "story_id": 300584, "label": "How Hormuz oil shock is India's chance to reset its energy future", "why": "IEA flags Hormuz disruption as a major supply shock with India central to demand growth" }
]
}

direction already compares the reading with the one before, so you could post on direction == "rising" alone. Keeping the last level you saw also catches a jump in level that came in two steps between your polls.

A quiet sector had too little reporting to read: its score, level, direction and verdict are null. Skip it.

"""Post sector turns to a webhook. Run hourly."""
import json
import os
from pathlib import Path
import requests
API = "https://dash.alethman.com/api/v1"
HOOK = os.environ["WEBHOOK_URL"]
SEEN = Path("outlooks-seen.json")
WATCH = {"energy_power", "public_order_unrest"} # empty set: every sector
r = requests.get(f"{API}/outlooks", headers={"Authorization": f"Bearer {os.environ['ALETHMAN_KEY']}"}, timeout=30)
r.raise_for_status()
seen = json.loads(SEEN.read_text()) if SEEN.exists() else {}
for o in r.json()["data"]:
if o["quiet"] or (WATCH and o["sector"] not in WATCH):
continue
before = seen.get(o["sector"])
turned = before is not None and before != o["risk_level"]
if turned or o["direction"] == "rising":
drivers = "\n".join(f"• {d['label']}: {d['why']}" for d in o["drivers"][:3])
text = f"*{o['name']}*: {before or '?'} → *{o['risk_level']}* ({o['direction']})\n{o['verdict']}\n{drivers}"
requests.post(HOOK, json={"text": text}, timeout=30)
seen[o["sector"]] = o["risk_level"]
SEEN.write_text(json.dumps(seen))

The first run only records what it sees (except sectors already rising); after that, it posts on change.