]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sat, 15 Jul 2023 00:47:38 +0000 (02:47 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 15 Jul 2023 00:47:38 +0000 (02:47 +0200)
- init rows list
- log type and length
- check if 'domain' and 'severity' are part of 'block' dictionary

fba/networks/mastodon.py

index cc1f46398e20c428d37504318930dcb42d0f0f6f..4b6190254df7310d7db14ce8d8d79f20ad871e0c 100644 (file)
@@ -158,6 +158,7 @@ def fetch_blocks(domain: str, nodeinfo_url: str) -> list:
             headers,
             (config.get("connection_timeout"), config.get("read_timeout"))
         )
+        rows = list()
 
         logger.debug("data[]='%s'", type(data))
         if "error_message" in data:
@@ -165,7 +166,7 @@ def fetch_blocks(domain: str, nodeinfo_url: str) -> list:
             instances.set_last_error(domain, data)
             return blocklist
         elif "json" in data and "error" in data["json"]:
-            logger.warning("JSON API returned error message: '%s'", data['json']['error'])
+            logger.warning("JSON API returned error message: '%s'", data["json"]["error"])
             instances.set_last_error(domain, data)
             return blocklist
         else:
@@ -175,10 +176,12 @@ def fetch_blocks(domain: str, nodeinfo_url: str) -> list:
             logger.debug("Marking domain='%s' as successfully handled ...", domain)
             instances.set_success(domain)
 
+        logger.debug("rows[%s]()=%d", type(rows), len(rows))
         if len(rows) == 0:
             logger.debug("domain='%s' has returned zero rows, trying /about/more page ...", domain)
             rows = fetch_blocks_from_about(domain)
 
+        logger.debug("rows[%s]()=%d", type(rows), len(rows))
         if len(rows) > 0:
             logger.debug("Checking %d entries from domain='%s' ...", len(rows), domain)
             for block in rows:
@@ -187,6 +190,10 @@ def fetch_blocks(domain: str, nodeinfo_url: str) -> list:
                 if not isinstance(block, dict):
                     logger.debug("block[]='%s' is of type 'dict' - SKIPPED!", type(block))
                     continue
+                elif "domain" not in block:
+                    logger.warning("block()=%d does not contain element 'domain'", len(block))
+                elif "severity" not in block:
+                    logger.warning("block()=%d does not contain element 'severity'", len(block))
 
                 reason = tidyup.reason(block["comment"]) if "comment" in block and block["comment"] is not None and block["comment"] != "" else None