Fetch solar conditions from HamQSL #92

This commit is contained in:
Ian Renton
2026-03-28 10:04:29 +00:00
parent ce99bbc6cf
commit 1173af6a9d
20 changed files with 526 additions and 29 deletions

View File

@@ -8,6 +8,7 @@ import sys
from diskcache import Cache
from core.cleanup import CleanupTimer
from data.solar_conditions import SolarConditions
from core.config import config, WEB_SERVER_PORT, SERVER_OWNER_CALLSIGN
from core.constants import SOFTWARE_NAME, SOFTWARE_VERSION
from core.lookup_helper import lookup_helper
@@ -17,10 +18,12 @@ from server.webserver import WebServer
# Globals
spots = Cache('cache/spots_cache')
alerts = Cache('cache/alerts_cache')
solar_conditions = SolarConditions()
web_server = None
status_data = {}
spot_providers = []
alert_providers = []
solar_condition_providers = []
cleanup_timer = None
run = True
@@ -38,6 +41,9 @@ def shutdown(sig, frame):
for ap in alert_providers:
if ap.enabled:
ap.stop()
for scp in solar_condition_providers:
if scp.enabled:
scp.stop()
cleanup_timer.stop()
lookup_helper.stop()
spots.close()
@@ -61,6 +67,14 @@ def get_alert_provider_from_config(config_providers_entry):
return provider_class(config_providers_entry)
def get_solar_conditions_provider_from_config(config_providers_entry):
"""Utility method to get a solar conditions provider based on the class specified in its config entry."""
module = importlib.import_module('solarconditionsproviders.' + config_providers_entry["class"].lower())
provider_class = getattr(module, config_providers_entry["class"])
return provider_class(config_providers_entry)
# Main function
if __name__ == '__main__':
# Set up logging
@@ -83,7 +97,7 @@ if __name__ == '__main__':
lookup_helper.start()
# Set up web server
web_server = WebServer(spots=spots, alerts=alerts, status_data=status_data, port=WEB_SERVER_PORT)
web_server = WebServer(spots=spots, alerts=alerts, solar_conditions=solar_conditions, status_data=status_data, port=WEB_SERVER_PORT)
# Fetch, set up and start spot providers
for entry in config["spot-providers"]:
@@ -101,6 +115,14 @@ if __name__ == '__main__':
if p.enabled:
p.start()
# Fetch, set up and start solar conditions providers
for entry in config.get("solar-condition-providers", []):
solar_condition_providers.append(get_solar_conditions_provider_from_config(entry))
for p in solar_condition_providers:
p.setup(solar_conditions=solar_conditions)
if p.enabled:
p.start()
# Set up timer to clear spot list of old data
cleanup_timer = CleanupTimer(spots=spots, alerts=alerts, web_server=web_server, cleanup_interval=60)
cleanup_timer.start()
@@ -108,7 +130,8 @@ if __name__ == '__main__':
# Set up status reporter
status_reporter = StatusReporter(status_data=status_data, spots=spots, alerts=alerts, web_server=web_server,
cleanup_timer=cleanup_timer, spot_providers=spot_providers,
alert_providers=alert_providers, run_interval=5)
alert_providers=alert_providers,
solar_condition_providers=solar_condition_providers, run_interval=5)
status_reporter.start()
logging.info("Startup complete.")