]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Mon, 12 Jun 2023 10:25:17 +0000 (12:25 +0200)
committerRoland Häder <roland@mxchange.org>
Mon, 12 Jun 2023 10:27:34 +0000 (12:27 +0200)
- renamed hash -> blocked_hash to avoid redefining builtin references
- also combined 2 isinstance() into one

fba/commands.py
fba/fba.py
fba/instances.py

index 534c861d0f2dd2090cb42ba4cf1e422998c1e3f0..96018e9d9803b86550f6736e86ebbc659b999d56 100644 (file)
@@ -568,7 +568,7 @@ def fetch_oliphant(args: argparse.Namespace):
                     print(f"WARNING: domain='{domain}' is not a valid domain - skipped!")
                     continue
                 elif blacklist.is_blacklisted(domain):
-                    print(f"WARNING: domain='{domain}' is blacklisted - skipped!")
+                    # DEBUG: print(f"DEBUG: domain='{domain}' is blacklisted - skipped!")
                     continue
                 elif instances.is_recent(domain):
                     # DEBUG: print(f"DEBUG: domain='{domain}' has been recently checked - skipped!")
index 9cd6b9c58f1c9bdfd94068df7b42fedeb587b4b3..d935bcbbd03bbefed7159d52b54fee7530c04c2a 100644 (file)
@@ -54,7 +54,7 @@ def log_error(domain: str, error: dict):
         return
 
     # DEBUG: print("DEBUG: BEFORE error[]:", type(error))
-    if isinstance(error, BaseException) or isinstance(error, json.decoder.JSONDecodeError):
+    if isinstance(error, BaseExceptionerror, json.decoder.JSONDecodeError):
         error = f"error[{type(error)}]='{str(error)}'"
 
     # DEBUG: print("DEBUG: AFTER error[]:", type(error))
index ec1dfb75d0083f4315528dd7e1cd0e9452a288e5..4cccb3770c307d059649369dda3b2f28afca4ff1 100644 (file)
@@ -264,7 +264,7 @@ def update_last_error(domain: str, error: dict):
         raise ValueError("Parameter 'domain' is empty")
 
     # DEBUG: print("DEBUG: BEFORE error[]:", type(error))
-    if isinstance(error, BaseException) or isinstance(error, json.decoder.JSONDecodeError):
+    if isinstance(error, (BaseException, json.decoder.JSONDecodeError)):
         error = f"error[{type(error)}]='{str(error)}'"
     # DEBUG: print("DEBUG: AFTER error[]:", type(error))
 
@@ -276,6 +276,8 @@ def update_last_error(domain: str, error: dict):
         # DEBUG: print(f"DEBUG: Setting last_error_details='{error.reason}'")
         set_data("last_status_code"  , domain, error.status_code)
         set_data("last_error_details", domain, error.reason)
+    elif not isinstance(error, dict):
+        raise KeyError(f"Cannot handle keys in error[{type(error)}]='{error}'")
     elif "status_code" in error and "error_message" in error:
         # DEBUG: print(f"DEBUG: Setting last_error_details='{error['error_message']}'")
         set_data("last_status_code"  , domain, error["status_code"])
@@ -283,8 +285,6 @@ def update_last_error(domain: str, error: dict):
     elif "json" in error and "error" in error["json"]:
         set_data("last_status_code"  , domain, error["status_code"])
         set_data("last_error_details", domain, error["json"]["error"])
-    else:
-        raise KeyError(f"Cannot handle keys in error[{type(error)}]='{error}'")
 
     # Running pending updated
     # DEBUG: print(f"DEBUG: Invoking update_data({domain}) ...")
@@ -337,8 +337,8 @@ def is_recent(domain: str) -> bool:
     # DEBUG: print(f"DEBUG: recently='{recently}' - EXIT!")
     return recently
 
-def deobsure(char: str, domain: str, hash: str = None) -> tuple:
-    #print(f"DEBUG: char='{char}',domain='{domain}',hash='{hash}' - CALLED!")
+def deobsure(char: str, domain: str, blocked_hash: str = None) -> tuple:
+    #print(f"DEBUG: char='{char}',domain='{domain}',blocked_hash='{blocked_hash}' - CALLED!")
     if not isinstance(char, str):
         raise ValueError(f"Parameter char[]='{type(char)}' is not 'str'")
     elif char == "":
@@ -347,12 +347,12 @@ def deobsure(char: str, domain: str, hash: str = None) -> tuple:
         raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
     elif domain == "":
         raise ValueError("Parameter 'domain' is empty")
-    elif not isinstance(hash, str) and hash is not None:
-        raise ValueError(f"Parameter hash[]='{type(hash)}' is not 'str'")
+    elif not isinstance(blocked_hash, str) and blocked_hash is not None:
+        raise ValueError(f"Parameter blocked_hash[]='{type(blocked_hash)}' is not 'str'")
 
-    if isinstance(hash, str):
+    if isinstance(blocked_hash, str):
         fba.cursor.execute(
-            "SELECT domain, origin, nodeinfo_url FROM instances WHERE hash = ? LIMIT 1", [hash]
+            "SELECT domain, origin, nodeinfo_url FROM instances WHERE hash = ? LIMIT 1", [blocked_hash]
         )
     else:
         fba.cursor.execute(