import csv from pyhamtools.locator import latlong_to_locator from data.sig_ref import SIGRef from sigrefdataproviders.file_download_sig_ref_data_provider import FileDownloadSIGRefDataProvider class SOTA(FileDownloadSIGRefDataProvider): """SIG ref data provider for Summits on the Air""" POLL_INTERVAL_DAYS = 30 SIG = "SOTA" DATA_URL = "https://storage.sota.org.uk/summitslist.csv" def __init__(self, provider_config): super().__init__(self.SIG, provider_config, self.DATA_URL, self.POLL_INTERVAL_DAYS) def _http_response_to_data(self, http_response): new_data = [] for row in csv.DictReader(http_response.content.decode("utf-8-sig").splitlines()[1:]): ref_id = row["SummitCode"] latitude = float(row["Latitude"]) if "Latitude" in row and row["Latitude"] != "" else None longitude = float(row["Longitude"]) if "Longitude" in row and row["Longitude"] != "" else None ref = SIGRef(sig=self.SIG, id=ref_id, name=row["SummitName"] if "SummitName" in row else None, url="https://www.sotadata.org.uk/en/summit/" + ref_id, latitude=latitude, longitude=longitude, activation_score=int(row["Points"]) if "Points" in row else None) if latitude and longitude: ref.grid = latlong_to_locator(latitude, longitude, 6) new_data.append(ref) return new_data