Extract config into yaml

This commit is contained in:
Ian Renton
2025-09-27 14:54:14 +01:00
parent 6d735cfc67
commit 00c56a7c10
9 changed files with 48 additions and 14 deletions

1
.gitignore vendored
View File

@@ -4,3 +4,4 @@ __pycache__
*.pyc *.pyc
/sota_summit_data_cache.sqlite /sota_summit_data_cache.sqlite
/gma_ref_info_cache.sqlite /gma_ref_info_cache.sqlite
/config.yml

View File

@@ -1,4 +1,4 @@
# MetaSpot # Amateur Radio meta spotting tool, name TBD
*Work in progress.* *Work in progress.*
@@ -31,4 +31,14 @@ Suggested names so far:
* Spot-o-Tron * Spot-o-Tron
* Basic Universal Radio Program (BURP) * Basic Universal Radio Program (BURP)
* The Spotinator * The Spotinator
* DX Cluster API * Spotcaster
* DX Cluster API
* spotcollector
* Unified Amateur Radio Data Aggregator (U-ARDA)
* (s)pothole
* Spot on API
* API on Spot
### TODO - Setup instructions - checkout, config.yml, pip
### TODO - systemd
### TODO - nginx

12
config-example.yml Normal file
View File

@@ -0,0 +1,12 @@
# Config file example.
# Rename this to "config.yml" before running the software.
# Your callsign. Used to log into DX clusters and included in User-Agent when querying HTTP servers. Useful so if your
# server goes crazy and causes other people problems, they know who to contact :)
server-owner-callsign: "N0CALL"
# Port to open the local web server on
web-server-port: 8080
# Maximum spot age to keep in the system before deleting it
max-spot-age-sec: 3600

13
core/config.py Normal file
View File

@@ -0,0 +1,13 @@
import logging
import os
import yaml
# Check you have a config file
if not os.path.isfile("config.yml"):
logging.error("Your config file is missing. Ensure you have copied config-example.yml to config.yml and updated it according to your needs.")
exit()
# Load config
config = yaml.safe_load(open("config.yml"))
logging.info("Loaded config.")

View File

@@ -4,11 +4,6 @@ from data.band import Band
SOFTWARE_NAME = "Metaspot by M0TRT" SOFTWARE_NAME = "Metaspot by M0TRT"
SOFTWARE_VERSION = "0.1" SOFTWARE_VERSION = "0.1"
# Todo make configurable
SERVER_OWNER_CALLSIGN = "M0TRT"
WEB_SERVER_PORT = 8080
MAX_SPOT_AGE_SEC = 3600
# Modes # Modes
CW_MODES = ["CW"] CW_MODES = ["CW"]
PHONE_MODES = ["PHONE", "SSB", "USB", "LSB", "AM", "FM", "DV", "DMR", "DSTAR", "C4FM", "M17"] PHONE_MODES = ["PHONE", "SSB", "USB", "LSB", "AM", "FM", "DV", "DMR", "DSTAR", "C4FM", "M17"]

View File

@@ -5,7 +5,7 @@ import sys
from time import sleep from time import sleep
from core.cleanup import CleanupTimer from core.cleanup import CleanupTimer
from core.constants import MAX_SPOT_AGE_SEC, WEB_SERVER_PORT from core.config import config
from providers.dxcluster import DXCluster from providers.dxcluster import DXCluster
from providers.gma import GMA from providers.gma import GMA
from providers.hema import HEMA from providers.hema import HEMA
@@ -63,11 +63,11 @@ if __name__ == '__main__':
for p in providers: p.start() for p in providers: p.start()
# Set up timer to clear spot list of old data # Set up timer to clear spot list of old data
cleanup_timer = CleanupTimer(spot_list=spot_list, cleanup_interval=60, max_spot_age=MAX_SPOT_AGE_SEC) cleanup_timer = CleanupTimer(spot_list=spot_list, cleanup_interval=60, max_spot_age=config["max-spot-age-sec"])
cleanup_timer.start() cleanup_timer.start()
# Set up web server # Set up web server
web_server = WebServer(spot_list=spot_list, port=WEB_SERVER_PORT) web_server = WebServer(spot_list=spot_list, port=config["web-server-port"])
web_server.start() web_server.start()
logging.info("Startup complete.") logging.info("Startup complete.")

View File

@@ -7,10 +7,11 @@ from time import sleep
import pytz import pytz
import telnetlib3 import telnetlib3
from core.constants import SERVER_OWNER_CALLSIGN
from data.spot import Spot from data.spot import Spot
from core.config import config
from providers.provider import Provider from providers.provider import Provider
# Provider for a DX Cluster. Hostname and port provided as parameters. # Provider for a DX Cluster. Hostname and port provided as parameters.
class DXCluster(Provider): class DXCluster(Provider):
CALLSIGN_PATTERN = "([a-z|0-9|/]+)" CALLSIGN_PATTERN = "([a-z|0-9|/]+)"
@@ -49,7 +50,7 @@ class DXCluster(Provider):
logging.info("DX Cluster " + self.hostname + " connecting...") logging.info("DX Cluster " + self.hostname + " connecting...")
self.telnet = telnetlib3.Telnet(self.hostname, self.port) self.telnet = telnetlib3.Telnet(self.hostname, self.port)
self.telnet.read_until("login: ".encode("utf-8")) self.telnet.read_until("login: ".encode("utf-8"))
self.telnet.write((SERVER_OWNER_CALLSIGN + "\n").encode("utf-8")) self.telnet.write((config["server-owner-callsign"] + "\n").encode("utf-8"))
connected = True connected = True
logging.info("DX Cluster " + self.hostname + " connected.") logging.info("DX Cluster " + self.hostname + " connected.")
except Exception as e: except Exception as e:

View File

@@ -2,14 +2,15 @@ from datetime import datetime
import pytz import pytz
from core.constants import SOFTWARE_NAME, SOFTWARE_VERSION, SERVER_OWNER_CALLSIGN from core.constants import SOFTWARE_NAME, SOFTWARE_VERSION
from core.config import config
# Generic data provider class. Subclasses of this query the individual APIs for data. # Generic data provider class. Subclasses of this query the individual APIs for data.
class Provider: class Provider:
# HTTP headers used for providers that use HTTP # HTTP headers used for providers that use HTTP
HTTP_HEADERS = { "User-Agent": SOFTWARE_NAME + " " + SOFTWARE_VERSION + " (operated by " + SERVER_OWNER_CALLSIGN + ")" } HTTP_HEADERS = { "User-Agent": SOFTWARE_NAME + " " + SOFTWARE_VERSION + " (operated by " + config["server-owner-callsign"] + ")" }
# Constructor # Constructor
def __init__(self): def __init__(self):

View File

@@ -1,3 +1,4 @@
pyyaml~=6.0.3
bottle~=0.13.4 bottle~=0.13.4
requests-cache~=1.2.1 requests-cache~=1.2.1
pyhamtools~=0.12.0 pyhamtools~=0.12.0