Spotting tweaks. Closes #2

This commit is contained in:
Ian Renton
2025-10-04 16:26:34 +01:00
parent 5f16abf709
commit d19ba1d662
3 changed files with 16 additions and 4 deletions

View File

@@ -70,4 +70,7 @@ max-spot-age-sec: 3600
# Login for QRZ.com to look up information. Optional. # Login for QRZ.com to look up information. Optional.
qrz-username: "N0CALL" qrz-username: "N0CALL"
qrz-password: "" qrz-password: ""
# Allow submitting spots to the Spothole API?
allow-spotting: true

View File

@@ -14,4 +14,5 @@ logging.info("Loaded config.")
MAX_SPOT_AGE = config["max-spot-age-sec"] MAX_SPOT_AGE = config["max-spot-age-sec"]
SERVER_OWNER_CALLSIGN = config["server-owner-callsign"] SERVER_OWNER_CALLSIGN = config["server-owner-callsign"]
WEB_SERVER_PORT = config["web-server-port"] WEB_SERVER_PORT = config["web-server-port"]
ALLOW_SPOTTING = config["allow-spotting"]

View File

@@ -8,7 +8,7 @@ import bottle
import pytz import pytz
from bottle import run, response, template from bottle import run, response, template
from core.config import MAX_SPOT_AGE from core.config import MAX_SPOT_AGE, ALLOW_SPOTTING
from core.constants import BANDS, ALL_MODES, MODE_TYPES, SIGS, CONTINENTS from core.constants import BANDS, ALL_MODES, MODE_TYPES, SIGS, CONTINENTS
from core.utils import serialize_everything from core.utils import serialize_everything
from data.spot import Spot from data.spot import Spot
@@ -64,6 +64,12 @@ class WebServer:
self.status = "OK" self.status = "OK"
try: try:
# Reject if not allowed
if not ALLOW_SPOTTING:
response.content_type = 'application/json'
response.status = 401
return json.dumps("Error - this server does not allow new spots to be added via the API.", default=serialize_everything)
# Reject if no spot # Reject if no spot
if not bottle.request.query.spot: if not bottle.request.query.spot:
response.content_type = 'application/json' response.content_type = 'application/json'
@@ -81,6 +87,8 @@ class WebServer:
return json.dumps("Error - 'time' and 'dx_call' must be provided as a minimum.", default=serialize_everything) return json.dumps("Error - 'time' and 'dx_call' must be provided as a minimum.", default=serialize_everything)
# infer missing data, and add it to our database. # infer missing data, and add it to our database.
spot.source = "API"
spot.icon = "desktop"
spot.infer_missing() spot.infer_missing()
self.spots.add(spot.guid, spot, expire=MAX_SPOT_AGE) self.spots.add(spot.guid, spot, expire=MAX_SPOT_AGE)
@@ -91,7 +99,7 @@ class WebServer:
logging.error(e) logging.error(e)
response.content_type = 'application/json' response.content_type = 'application/json'
response.status = 422 response.status = 422
return json.dumps("An error occurred parsing your spot: " + str(e), default=serialize_everything) return json.dumps("Error - " + str(e), default=serialize_everything)
# Serve a templated page # Serve a templated page
def serve_template(self, template_name): def serve_template(self, template_name):