#!/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())