]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Fri, 7 Jul 2023 20:42:51 +0000 (22:42 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 7 Jul 2023 20:42:51 +0000 (22:42 +0200)
- check response.status_code and length of response.text
- handle None (NULL) values for last_updated/last_seen

daemon.py

index 459f0fc22967d522da551677d4ccd5cc23d9b729..71e76cef28cd5536eadd630631adc9b09d3931f6 100755 (executable)
--- a/daemon.py
+++ b/daemon.py
@@ -326,7 +326,7 @@ def list_domains(request: Request, mode: str, value: str, amount: int = config.g
         format = config.get("timestamp_format")
         for row in domainlist:
             row["first_seen"]   = datetime.utcfromtimestamp(row["first_seen"]).strftime(format)
-            row["last_updated"] = datetime.utcfromtimestamp(row["last_updated"]).strftime(format)
+            row["last_updated"] = datetime.utcfromtimestamp(row["last_updated"]).strftime(format) if isinstance(row["last_updated"], float) else None
 
     return templates.TemplateResponse("views/list.html", {
         "request"   : request,
@@ -350,14 +350,14 @@ def top(request: Request, mode: str, value: str, amount: int = config.get("api_l
 
     found = 0
     blocklist = list()
-    if response is not None and response.ok:
+    if response is not None and response.ok and response.status_code >= 300 and len(response.text) > 0:
         blocklist = response.json()
 
         format = config.get("timestamp_format")
         for block_level in blocklist:
-            for block in blocklist[block_level]:
-                block["first_seen"] = datetime.utcfromtimestamp(block["first_seen"]).strftime(format)
-                block["last_seen"]  = datetime.utcfromtimestamp(block["last_seen"]).strftime(format)
+            for row in blocklist[block_level]:
+                row["first_seen"] = datetime.utcfromtimestamp(row["first_seen"]).strftime(format)
+                row["last_seen"]  = datetime.utcfromtimestamp(row["last_seen"]).strftime(format) if isinstance(row["last_updated"], float) else None
                 found = found + 1
 
     return templates.TemplateResponse("views/top.html", {
@@ -381,7 +381,7 @@ def rss(request: Request, domain: str):
 
     response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/domain.json?domain={domain}")
 
-    if not response.ok or response.status_code > 200 or response.text.strip() == "":
+    if not response.ok or response.status_code >= 300 or response.text.strip() == "":
         raise HTTPException(status_code=response.status_code, detail=response.reason)
 
     domain_data = response.json()
@@ -390,9 +390,9 @@ def rss(request: Request, domain: str):
     format = config.get("timestamp_format")
     instance = dict()
     for key in domain_data.keys():
-        if key in ["last_nodeinfo", "last_blocked", "first_seen", "last_updated", "last_instance_fetch"]:
+        if key in ["last_nodeinfo", "last_blocked", "first_seen", "last_updated", "last_instance_fetch"] and isinstance(domain_data, float):
             # Timestamps
-            instance[key] = datetime.utcfromtimestamp(domain_data[key]).strftime(format) if isinstance(domain_data[key], float) else "-"
+            instance[key] = datetime.utcfromtimestamp(domain_data[key]).strftime(format)
         else:
             # Generic
             instance[key] = domain_data[key]