feat: add nowcast point alarm update client with dry-run

Patches registrations from CSV rows, sending only non-blank cells, validating lat/lng pairing and ranges locally, warning about the speedThreshold PATCH gap (GAIA-476) and recording status, httpStatus and errorBody back into the CSV.
This commit is contained in:
2026-10-23 19:13:35 +03:00
parent ba249128a1
commit 8587669ea5
4 changed files with 290 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
#!/usr/bin/env python3
"""Patch point alarm registrations from a CSV file (blank cells are not sent)."""
from __future__ import annotations
import argparse
import logging
import sys
from pathlib import Path
from common import ApiError, ConfigurationError, IklimClient, configure_logging
from point_alarm import PointAlarmService, PointUpdateProcessor
BASE_DIR = Path(__file__).resolve().parent
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description=(
"CSV satırlarından nokta alarm kayıtlarını kısmen günceller (PATCH). Sütunlar: "
"registrationId (zorunlu) ve isteğe bağlı recipientId;lat;lng;radius;lightningType;"
"peakCurrent;inCloudHeight;intersectsAffectedPolygon;intersectsCellPolygon;"
"severityThreshold;speedThreshold;precipitationIntensities ('|' ile ayrılır). Boş hücre "
"gönderilmez; lat ve lng birlikte verilmelidir. Bir alan boşaltılamaz (temizleme "
"desteklenmez). thunderstorm.speedThreshold backend PATCH'inde işlenmiyor (GAIA-476). "
"Sonuç sütunları status;httpStatus;errorBody aynı dosyaya yazılır."
)
)
parser.add_argument("csv_file", type=Path, help="İşlenecek noktalı virgüllü CSV")
parser.add_argument(
"--dry-run",
action="store_true",
help="İstek göndermeden ve CSV'yi değiştirmeden PATCH gövdelerini ekrana yazar",
)
parser.add_argument(
"--debug-log",
type=Path,
default=BASE_DIR / "logs" / "iklim-api-debug.log",
help="Maskelenmiş HTTP debug log dosyası",
)
return parser.parse_args()
def main() -> int:
args = parse_args()
configure_logging(args.debug_log)
try:
client = IklimClient.from_env(BASE_DIR / ".env")
PointUpdateProcessor(
PointAlarmService(client), csv_path=args.csv_file, dry_run=args.dry_run
).run()
except (ConfigurationError, ApiError, OSError) as exc:
logging.error("İşlem durduruldu: %s", exc)
return 1
return 0
if __name__ == "__main__":
sys.exit(main())