mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-06-24 05:35:10 +00:00
Implement spotting to Tiles on the Air. #95
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
from datetime import datetime
|
||||
|
||||
import requests
|
||||
|
||||
from core.constants import HTTP_HEADERS, SSB_SUB_MODES
|
||||
from data.sig_ref import SIGRef
|
||||
from data.spot import Spot
|
||||
from spotproviders.http_spot_provider import HTTPSpotProvider
|
||||
@@ -10,6 +13,8 @@ class Tiles(HTTPSpotProvider):
|
||||
|
||||
POLL_INTERVAL_SEC = 120
|
||||
SPOTS_URL = "https://icneuzxitdqtofutxbla.supabase.co/functions/v1/spots?active_hours=24"
|
||||
SUBMIT_URL = "https://icneuzxitdqtofutxbla.supabase.co/functions/v1/self-spot"
|
||||
VALID_MODES = ["SSB", "CW", "FT8", "FT4", "FM", "DMR", "D-STAR", "M17", "AX.25", "JS8Call", "PSK31", "Olivia", "VarAC", "Other"]
|
||||
|
||||
def __init__(self, provider_config):
|
||||
super().__init__(provider_config, self.SPOTS_URL, self.POLL_INTERVAL_SEC)
|
||||
@@ -41,6 +46,48 @@ class Tiles(HTTPSpotProvider):
|
||||
new_spots.append(spot)
|
||||
return new_spots
|
||||
|
||||
def can_submit_spot(self, sig):
|
||||
return sig == "Tiles"
|
||||
|
||||
def submit_spot(self, spot, credentials):
|
||||
# Tiles on the air currently only supports *self* spots
|
||||
if spot.dx_call == spot.de_call:
|
||||
|
||||
# Figure out a valid mode. Borrowed this from PoLo :)
|
||||
# https://github.com/ham2k/app-polo/blob/main/src/extensions/activities/sota/SOTAPostSelfSpot.js
|
||||
if spot.mode:
|
||||
mode = spot.mode
|
||||
if mode not in self.VALID_MODES:
|
||||
if mode in SSB_SUB_MODES:
|
||||
mode = "SSB"
|
||||
elif mode == "OLIVIA":
|
||||
mode = "Olivia"
|
||||
elif mode == "JS8":
|
||||
mode = "JS8Call"
|
||||
else:
|
||||
mode = "Other"
|
||||
|
||||
body = {
|
||||
"call_sign": spot.dx_call,
|
||||
"frequency": str(spot.freq / 1000000.0),
|
||||
"mode": mode or "",
|
||||
"grid": spot.dx_grid or "",
|
||||
"comment": spot.comment or "",
|
||||
"lat": spot.dx_latitude or None,
|
||||
"lon": spot.dx_longitude or None,
|
||||
"qrt": spot.qrt or False,
|
||||
"pin": credentials.get("offline_spot_gateway_pin", "")
|
||||
}
|
||||
headers = {**HTTP_HEADERS, "Content-Type": "application/json"}
|
||||
response = requests.post(self.SUBMIT_URL, json=body, headers=headers, timeout=(5, 30))
|
||||
if not response.ok:
|
||||
raise RuntimeError("Tiles on the Air API returned " + str(response.status_code) + ": " + response.text)
|
||||
else:
|
||||
raise RuntimeError("The Tiles on the Air API requires a mode to be set.")
|
||||
else:
|
||||
raise RuntimeError("The Tiles on the Air API only supports self-spots, the DX call and spotter call must match.")
|
||||
|
||||
|
||||
# Utility function to keep the first decimal point in a given string but remove any others. Used to parse Tiles'
|
||||
# strange frequency format where we can sometimes have e.g. "14.123.5".
|
||||
def strip_extra_decimal_points(s):
|
||||
|
||||
Reference in New Issue
Block a user