feat: add nowcast point alarm register client

Registers one point alarm per CSV row (recipientId, lat, lng, radius) with the shared filter JSON and the existing webhook bootstrap, records status, httpStatus, registrationId and errorBody back into the CSV and recovers ambiguous failures only on an identical recipient, point and radius match.
This commit is contained in:
2026-10-23 19:13:01 +03:00
parent 32a587a1c6
commit ba249128a1
4 changed files with 341 additions and 2 deletions
+68
View File
@@ -0,0 +1,68 @@
#!/usr/bin/env python3
"""Create point alarm registrations for every eligible row in a CSV file."""
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, PointRegistrationProcessor
BASE_DIR = Path(__file__).resolve().parent
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description=(
"CSV satırlarından iklim.co nokta alarm kayıtları oluşturur. CSV sütunları: "
"recipientId;lat;lng;radius (radius metre, 0-50000). Filtre ortak JSON dosyasından "
"okunur. Sonuç sütunları (status;httpStatus;registrationId;errorBody) aynı dosyaya "
"yazılır; SUCCESS satırlar yeniden çalıştırmada atlanır."
)
)
parser.add_argument("csv_file", type=Path, help="İşlenecek noktalı virgüllü CSV")
parser.add_argument(
"--webhook-config",
type=Path,
default=BASE_DIR / "webhook.json",
help="Webhook JSON dosyası (varsayılan: webhook.json)",
)
parser.add_argument(
"--filter-config",
type=Path,
default=BASE_DIR / "nowcast-point-alarm-filter.json",
help="Her kayda uygulanan filtre JSON dosyası (varsayılan: nowcast-point-alarm-filter.json)",
)
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")
PointRegistrationProcessor(
PointAlarmService(client),
csv_path=args.csv_file,
webhook_config_path=args.webhook_config,
filter_config_path=args.filter_config,
).run()
except (ConfigurationError, ApiError, OSError) as exc:
logging.error("İşlem durduruldu: %s", exc)
return 1
logging.info("CSV işlemi tamamlandı: %s", args.csv_file.resolve())
return 0
if __name__ == "__main__":
sys.exit(main())