mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-06 18:41:41 +00:00
Refactor of caching & data storage part 3 #118
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
from pyhamtools.locator import latlong_to_locator
|
||||
|
||||
from data.sig_ref import SIGRef
|
||||
from sigrefdataproviders.file_download_sig_ref_data_provider import FileDownloadSIGRefDataProvider
|
||||
|
||||
|
||||
class ZLOTA(FileDownloadSIGRefDataProvider):
|
||||
"""SIG ref data provider for New Zealand on the Air"""
|
||||
|
||||
POLL_INTERVAL_SEC = 30 * 24 * 60 * 60 # 30 days
|
||||
SIG = "ZLOTA"
|
||||
DATA_URL = "https://ontheair.nz/assets/assets.json"
|
||||
|
||||
def __init__(self, provider_config):
|
||||
super().__init__(self.SIG, provider_config, self.DATA_URL, self.POLL_INTERVAL_SEC)
|
||||
|
||||
def _http_response_to_data(self, http_response):
|
||||
new_data = {}
|
||||
data = http_response.json()
|
||||
if isinstance(data, list):
|
||||
for ref in data:
|
||||
ref_id = ref["code"]
|
||||
latitude = ref["y"]
|
||||
longitude = ref["x"]
|
||||
|
||||
new_data[ref_id] = SIGRef(sig=self.SIG, id=ref_id, name=ref["name"],
|
||||
url="https://ontheair.nz/assets/" + ref_id.replace("/", "_"),
|
||||
latitude=latitude,
|
||||
longitude=longitude)
|
||||
if latitude and longitude:
|
||||
new_data[ref_id].grid = latlong_to_locator(latitude, longitude, 6)
|
||||
|
||||
return new_data
|
||||
Reference in New Issue
Block a user