Files
iklim-sandbox/nowcast-geo-register.py
T
2026-09-09 16:21:13 +03:00

69 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""Create geo 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 geo_alarm import CsvRegistrationProcessor, GeoAlarmService
BASE_DIR = Path(__file__).resolve().parent
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="CSV satırlarından iklim.co coğrafi alarm kayıtları oluşturur."
)
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(
"--nowcast-filter-config",
type=Path,
default=BASE_DIR / "nowcast-geo-alarm-filter.json",
help=(
"Nowcast geo alarm filter JSON dosyası "
"(varsayılan: nowcast-geo-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")
processor = CsvRegistrationProcessor(
GeoAlarmService(client),
csv_path=args.csv_file,
webhook_config_path=args.webhook_config,
nowcast_filter_config_path=args.nowcast_filter_config,
)
processor.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())