mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-10-27 16:59:25 +00:00
41 lines
2.0 KiB
Python
41 lines
2.0 KiB
Python
import logging
|
|
from datetime import datetime
|
|
|
|
import pytz
|
|
|
|
from data.spot import Spot
|
|
from spotproviders.http_spot_provider import HTTPSpotProvider
|
|
|
|
|
|
# Spot provider for Parks n Peaks
|
|
class ParksNPeaks(HTTPSpotProvider):
|
|
POLL_INTERVAL_SEC = 120
|
|
SPOTS_URL = "https://www.parksnpeaks.org/api/ALL"
|
|
|
|
def __init__(self, provider_config):
|
|
super().__init__(provider_config, self.SPOTS_URL, self.POLL_INTERVAL_SEC)
|
|
|
|
def http_response_to_spots(self, http_response):
|
|
new_spots = []
|
|
# Iterate through source data
|
|
for source_spot in http_response.json():
|
|
# Convert to our spot format
|
|
spot = Spot(source=self.name,
|
|
source_id=source_spot["actID"],
|
|
dx_call=source_spot["actCallsign"].upper(),
|
|
de_call=source_spot["actSpoter"].upper(), # typo exists in API
|
|
freq=float(source_spot["actFreq"].replace(",", "")) * 1000000 if (source_spot["actFreq"] != "") else None, # Seen PNP spots with empty frequency, and with comma-separated thousands digits
|
|
mode=source_spot["actMode"].upper(),
|
|
comment=source_spot["actComments"],
|
|
sig=source_spot["actClass"],
|
|
sig_refs=[source_spot["actSiteID"]],
|
|
icon="question", # todo determine from actClass
|
|
time=datetime.strptime(source_spot["actTime"], "%Y-%m-%d %H:%M:%S").replace(tzinfo=pytz.UTC).timestamp())
|
|
|
|
# If this is POTA, SOTA or WWFF data we already have it through other means, so ignore.
|
|
if spot.sig not in ["POTA", "SOTA", "WWFF"]:
|
|
logging.warn("PNP spot found with sig " + spot.sig + ", developer needs to figure out how to look this up for grid/lat/lon!")
|
|
# Add to our list. Don't worry about de-duping, removing old spots etc. at this point; other code will do
|
|
# that for us.
|
|
new_spots.append(spot)
|
|
return new_spots |