from datetime import datetime from typing import Any import pytz import requests from core.enums import ActivityName, Mode from data.activity_ref import ActivityRef from data.spot import Spot from providers.spot.http_spot_provider import HTTPSpotProvider class ZLOTA(HTTPSpotProvider): """Spot provider for ZLOTA""" POLL_INTERVAL_SEC = 120 SPOTS_URL = "https://ontheair.nz/api/spots?zlota_only=true" def __init__(self, provider_config: dict[str, Any]) -> None: super().__init__("ZLOTA", provider_config, self.SPOTS_URL, self.POLL_INTERVAL_SEC) def _http_response_to_spots(self, http_response: requests.Response) -> list[Spot]: new_spots: list[Spot] = [] # Iterate through source data for source_spot in http_response.json(): # Frequency is often inconsistent as to whether it's in Hz or kHz. Make a guess. freq_hz = float(source_spot["frequency"]) if freq_hz < 1000000: freq_hz = freq_hz * 1000 # Convert to our spot format spot = Spot( source=self.name, source_id=source_spot["id"], dx_call=source_spot["activator"].upper(), de_call=source_spot["spotter"].upper(), freq=freq_hz, mode=Mode.from_name(source_spot["mode"].upper().strip()), comment=source_spot["comments"], sig=ActivityName.ZLOTA, sig_refs=[ ActivityRef( id=source_spot["reference"], sig=ActivityName.ZLOTA, name=source_spot["name"], ) ], time=datetime.fromisoformat(source_spot["referenced_time"].replace("Z", "+00:00")) .astimezone(pytz.UTC) .timestamp(), ) new_spots.append(spot) return new_spots def can_submit_spot(self, activity: str) -> bool: return activity == ActivityName.ZLOTA def submit_spot(self, spot: Spot, credentials: dict[str, str]) -> None: # TODO: Implement. Spotting to ZLOTA is supported via POST, see https://ontheair.nz/api raise NotImplementedError("ZLOTA upstream spot submission is not yet implemented")