diff --git a/owrx/controllers/clients.py b/owrx/controllers/clients.py index 67ed0eb5..e20b9fce 100644 --- a/owrx/controllers/clients.py +++ b/owrx/controllers/clients.py @@ -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) ) diff --git a/owrx/controllers/services.py b/owrx/controllers/services.py index f7fc2ad6..7bb91ee3 100644 --- a/owrx/controllers/services.py +++ b/owrx/controllers/services.py @@ -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): {services} + {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 += "
\n" + result + "
\n" + @staticmethod def renderService(c): # Choose units based on frequency diff --git a/owrx/eibi.py b/owrx/eibi.py index 83265a06..e4242f68 100644 --- a/owrx/eibi.py +++ b/owrx/eibi.py @@ -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: diff --git a/owrx/repeaters.py b/owrx/repeaters.py index 6f052296..a4e9cd8e 100644 --- a/owrx/repeaters.py +++ b/owrx/repeaters.py @@ -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: