Now showing EIBI and repeaters last download times.

This commit is contained in:
Marat Fayzullin 2025-01-10 19:40:21 -05:00
parent 159989694a
commit 36ea6e7f52
4 changed files with 51 additions and 9 deletions

View File

@ -60,7 +60,7 @@ class ClientController(AuthorizationMixin, WebpageController):
c["name"] if "name" in c else "",
"banned" if c["ban"] else c["sdr"] + " " + c["band"] if "sdr" in c else "n/a",
"until" if c["ban"] else "since",
c["ts"].strftime('%H:%M:%S'),
c["ts"].strftime("%H:%M:%S"),
ClientController.renderButtons(c)
)

View File

@ -2,6 +2,9 @@ from owrx.controllers.admin import AuthorizationMixin
from owrx.controllers.template import WebpageController
from owrx.breadcrumb import Breadcrumb, BreadcrumbItem, BreadcrumbMixin
from owrx.service import Services
from owrx.repeaters import Repeaters
from owrx.eibi import EIBI
from datetime import datetime
import json
import re
@ -30,10 +33,29 @@ class ServiceController(AuthorizationMixin, WebpageController):
</tr>
{services}
</table>
{status}
""".format(
services="".join(ServiceController.renderService(c) for c in Services.listAll())
services="".join(ServiceController.renderService(c) for c in Services.listAll()),
status=ServiceController.renderStatus()
)
@staticmethod
def renderStatus():
result = ""
ts = Repeaters.lastDownloaded()
if ts > 0:
ts = datetime.fromtimestamp(ts).strftime("%H:%M:%S, %m/%d/%Y")
result += "<div style='color:green;width:100%;text-align:center;'>Repeaters database downloaded at {0}.</div>\n".format(ts)
else:
result += "<div style='color:red;width:100%;text-align:center;'>Repeaters database not downloaded.</div>\n"
ts = EIBI.lastDownloaded()
if ts > 0:
ts = datetime.fromtimestamp(ts).strftime("%H:%M:%S, %m/%d/%Y")
result += "<div style='color:green;width:100%;text-align:center;'>Shortwave schedule downloaded at {0}.</div>\n".format(ts)
else:
result += "<div style='color:red;width:100%;text-align:center;'>Shortwave schedule not downloaded.</div>\n"
return "<p style='width:100%;'>\n" + result + "</p>\n"
@staticmethod
def renderService(c):
# Choose units based on frequency

View File

@ -37,6 +37,18 @@ class EIBI(object):
coreConfig = CoreConfig()
return "{data_directory}/eibi.json".format(data_directory=coreConfig.get_data_directory())
# Get last downloaded timestamp or 0 for none
@staticmethod
def lastDownloaded():
try:
file = EIBI._getCachedScheduleFile()
if os.path.isfile(file) and os.path.getsize(file) > 0:
return os.path.getmtime(file)
else:
return 0
except Exception as e:
return 0
# Offset frequency for proper tuning
@staticmethod
def correctFreq(freq: int, mode: str) -> int:
@ -109,10 +121,8 @@ class EIBI(object):
def refresh(self):
# This file contains cached schedule
file = self._getCachedScheduleFile()
ts = os.path.getmtime(file) if os.path.isfile(file) else 0
# If cached schedule is stale...
if time.time() - ts >= self.refreshPeriod:
if time.time() - self.lastDownloaded() >= self.refreshPeriod:
# Load EIBI database file from the web
schedule = self.loadFromWeb()
if schedule:

View File

@ -34,6 +34,18 @@ class Repeaters(object):
coreConfig = CoreConfig()
return "{data_directory}/repeaters.json".format(data_directory=coreConfig.get_data_directory())
# Get last downloaded timestamp or 0 for none
@staticmethod
def lastDownloaded():
try:
file = Repeaters._getCachedDatabaseFile()
if os.path.isfile(file) and os.path.getsize(file) > 0:
return os.path.getmtime(file)
else:
return 0
except Exception as e:
return 0
# Compute distance, in kilometers, between two latlons.
@staticmethod
def distKm(p1, p2):
@ -115,12 +127,10 @@ class Repeaters(object):
# Load cached database or refresh it from the web.
#
def refresh(self):
# This file contains cached database
# This file contains cached repeaters database
file = self._getCachedDatabaseFile()
ts = os.path.getmtime(file) if os.path.isfile(file) else 0
# If cached database is stale...
if time.time() - ts >= self.refreshPeriod:
if time.time() - self.lastDownloaded() >= self.refreshPeriod:
# Load EIBI database file from the web
repeaters = self.loadFromWeb()
if repeaters: