Брифинг по полёту
Готовые к запуску примеры предполётных брифингов и брифингов на маршруте с использованием эндпоинта Брифинг по полёту. API возвращает сводку, сгенерированную моделью IBM Granite, вместе со структурированными разделами погоды и NOTAM.
| # | Вопрос | Используемые данные |
|---|---|---|
| 1 | Сгенерировать полный брифинг для KJFK → KLAX и вывести сводку | Брифинг по полёту |
| 2 | Вывести основные NOTAM из брифинга для EGLL → OMDB | Брифинг по полёту |
Требования
x-api-key в каждом запросе (прямая подписка). Подробнее →Установка
Приведённые ниже скрипты используют requests для вызовов API и rich для вывода в терминал. Установите один раз:
pip install requests rich1. Полная сводка брифинга по полёту
Вопрос: сгенерировать брифинг по полёту в формате JSON для KJFK → KLAX и вывести ИИ-сводку и погодные условия.
Ответ — это структурированный JSON с summary, origin_briefing и destination_briefing либо обычный текст с ключом briefing; скрипт обрабатывает оба варианта. Генерация брифинга может занимать до ~90 секунд; при 503 скрипт выполняет одну повторную попытку.
import os
import time
import requests
from rich.console import Console
from rich.panel import Panel
from rich.table import Table
console = Console()
HEADERS = {
"X-RapidAPI-Key": os.getenv("RAPIDAPI_KEY", "YOUR_RAPIDAPI_KEY"),
"X-RapidAPI-Host": "skylink-api.p.rapidapi.com",
}
BASE = "https://skylink-api.p.rapidapi.com"
def fetch_briefing(origin: str, destination: str) -> dict | None:
params = {
"origin": origin,
"destination": destination,
"include_weather": "true",
"include_notams": "true",
"format": "json",
}
for attempt in range(2):
try:
r = requests.get(
f"{BASE}/briefing/flight",
headers=HEADERS,
params=params,
timeout=(10, 100),
)
except requests.exceptions.Timeout:
if attempt == 0:
time.sleep(5)
continue
return None
if r.status_code == 404:
return None
if r.status_code in (502, 503, 504):
if attempt == 0:
time.sleep(8)
continue
return None
r.raise_for_status()
return r.json()
return None
def weather_snippet(airport_briefing: dict | None) -> str:
if not airport_briefing:
return "—"
wx = airport_briefing.get("weather") or {}
metar = wx.get("metar_raw")
if metar:
return metar[:72] + ("…" if len(metar) > 72 else "")
taf = wx.get("taf_raw")
if taf:
return f"TAF only: {taf[:60]}…"
return "No METAR/TAF in briefing"
def main() -> None:
data = fetch_briefing("KJFK", "KLAX")
if not data:
console.print("[yellow]No briefing returned.[/]")
return
if "briefing" in data and "summary" not in data:
console.print(Panel(data["briefing"], title="Flight Briefing (text)"))
return
summary = data.get("summary")
if summary:
console.print(Panel(summary, title="Briefing Summary (AI-generated — IBM Granite)"))
table = Table(title="Weather (METAR excerpt)")
table.add_column("Airport", style="cyan")
table.add_column("Observation")
origin = data.get("origin_briefing")
destination = data.get("destination_briefing")
table.add_row(f"Departure ({data.get('origin', 'KJFK')})", weather_snippet(origin))
table.add_row(f"Arrival ({data.get('destination', 'KLAX')})", weather_snippet(destination))
console.print(table)
restrictions = data.get("critical_restrictions") or []
if restrictions:
console.print(Panel("\n".join(f"• {x}" for x in restrictions), title="Critical restrictions"))
console.print(
"\n[dim]Briefing summary is AI-generated. Always verify critical weather "
"conditions directly against METAR and TAF before flight.[/dim]"
)
if __name__ == "__main__":
main()Результат: панель со сводкой, сгенерированной ИИ, таблица с выдержками из METAR для аэропортов вылета и прилёта и, при наличии, маркированный список критических ограничений. Если API возвращает строку briefing вместо структурированного JSON, скрипт переключается на вывод обычного текста.
2. Основные NOTAM из брифинга
Вопрос: какие NOTAM действуют в аэропортах вылета и прилёта на маршруте EGLL → OMDB?
import os
import time
import requests
from rich.console import Console
from rich.panel import Panel
from rich.table import Table
console = Console()
HEADERS = {
"X-RapidAPI-Key": os.getenv("RAPIDAPI_KEY", "YOUR_RAPIDAPI_KEY"),
"X-RapidAPI-Host": "skylink-api.p.rapidapi.com",
}
BASE = "https://skylink-api.p.rapidapi.com"
def fetch_briefing(origin: str, destination: str) -> dict | None:
params = {
"origin": origin,
"destination": destination,
"include_weather": "false",
"include_notams": "true",
"format": "json",
}
for attempt in range(2):
try:
r = requests.get(
f"{BASE}/briefing/flight",
headers=HEADERS,
params=params,
timeout=(10, 100),
)
except requests.exceptions.Timeout:
if attempt == 0:
time.sleep(5)
continue
return None
if r.status_code == 404:
return None
if r.status_code in (502, 503, 504):
if attempt == 0:
time.sleep(8)
continue
return None
r.raise_for_status()
return r.json()
return None
def print_notam_table(label: str, notams: list[dict]) -> None:
top = notams[:3]
table = Table(title=f"NOTAMs — {label} (top {len(top)})")
table.add_column("NOTAM ID", style="cyan", min_width=12)
table.add_column("Body (truncated)")
for notam in top:
notam_id = notam.get("notam_id") or notam.get("id") or "—"
body = notam.get("body") or notam.get("raw") or "—"
body_short = body[:80] + ("…" if len(body) > 80 else "")
table.add_row(str(notam_id), body_short)
console.print(table)
def main() -> None:
data = fetch_briefing("EGLL", "OMDB")
if not data:
console.print("[yellow]No briefing returned.[/]")
return
if "briefing" in data and "origin_briefing" not in data:
console.print(Panel(data["briefing"], title="Flight Briefing (text — no structured NOTAMs)"))
return
origin = data.get("origin_briefing") or {}
destination = data.get("destination_briefing") or {}
dep_notams = origin.get("notams") or []
arr_notams = destination.get("notams") or []
if not dep_notams and not arr_notams:
console.print("[yellow]No NOTAMs embedded in briefing response.[/]")
summary = data.get("summary") or data.get("briefing")
if summary:
console.print(Panel(str(summary), title="Briefing summary"))
return
if dep_notams:
print_notam_table(f"Departure (EGLL) — {len(dep_notams)} total", dep_notams)
else:
console.print("[dim]No departure NOTAMs in briefing.[/]")
if arr_notams:
print_notam_table(f"Arrival (OMDB) — {len(arr_notams)} total", arr_notams)
else:
console.print("[dim]No arrival NOTAMs in briefing.[/]")
if __name__ == "__main__":
main()Результат: до трёх NOTAM на аэропорт из origin_briefing.notams и destination_briefing.notams. Если структурированный JSON недоступен, скрипт переключается на текстовое поле briefing.