]> git.mxchange.org Git - fba.git/blobdiff - fba/network.py
WIP:
[fba.git] / fba / network.py
index 7138e8cefdbe9bc900b994e9019e65c354c561fe..4894c0f7e9bfa17ac44eb22415867f742204cbd9 100644 (file)
@@ -67,8 +67,8 @@ def post_json_api(domain: str, path: str, parameter: str, extra_headers: dict =
             print(f"WARNING: Cannot query JSON API: domain='{domain}',path='{path}',parameter()={len(parameter)},response.status_code='{response.status_code}',data[]='{type(data)}'")
             instances.update_last_error(domain, response)
 
-    except BaseException as exc:
-        print(f"WARNING: Some error during post(): domain='{domain}',path='{path}',parameter()={len(parameter)},exc[{type(exc)}]:'{str(exc)}'")
+    except BaseException as exception:
+        print(f"WARNING: Some error during post(): domain='{domain}',path='{path}',parameter()={len(parameter)},exception[{type(exception)}]:'{str(exception)}'")
 
     # DEBUG: print(f"DEBUG: Returning data({len(data)})=[]:{type(data)}")
     return data
@@ -118,55 +118,6 @@ def send_bot_post(domain: str, blocklist: dict):
 
     return True
 
-def fetch_friendica_blocks(domain: str) -> dict:
-    # DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
-    if not isinstance(domain, str):
-        raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
-    elif domain == "":
-        raise ValueError("Parameter 'domain' is empty")
-
-    # DEBUG: print("DEBUG: Fetching friendica blocks from domain:", domain)
-    blocked = list()
-
-    try:
-        doc = bs4.BeautifulSoup(
-            fetch_response(domain, "/friendica", web_headers, (config.get("connection_timeout"), config.get("read_timeout"))).text,
-            "html.parser",
-        )
-    except BaseException as exc:
-        print("WARNING: Failed to fetch /friendica from domain:", domain, exc)
-        instances.update_last_error(domain, exc)
-        return {}
-
-    blocklist = doc.find(id="about_blocklist")
-
-    # Prevents exceptions:
-    if blocklist is None:
-        # DEBUG: print("DEBUG: Instance has no block list:", domain)
-        return {}
-
-    table = blocklist.find("table")
-
-    # DEBUG: print(f"DEBUG: table[]='{type(table)}'")
-    if table.find("tbody"):
-        rows = table.find("tbody").find_all("tr")
-    else:
-        rows = table.find_all("tr")
-
-    # DEBUG: print(f"DEBUG: Found rows()={len(rows)}")
-    for line in rows:
-        # DEBUG: print(f"DEBUG: line='{line}'")
-        blocked.append({
-            "domain": fba.tidyup_domain(line.find_all("td")[0].text),
-            "reason": fba.tidyup_reason(line.find_all("td")[1].text)
-        })
-        # DEBUG: print("DEBUG: Next!")
-
-    # DEBUG: print("DEBUG: Returning blocklist() for domain:", domain, len(blocklist))
-    return {
-        "reject": blocked
-    }
-
 def fetch_response(domain: str, path: str, headers: dict, timeout: list) -> requests.models.Response:
     # DEBUG: print(f"DEBUG: domain='{domain}',path='{path}',headers()={len(headers)},timeout={timeout} - CALLED!")
     if not isinstance(domain, str):
@@ -189,10 +140,10 @@ def fetch_response(domain: str, path: str, headers: dict, timeout: list) -> requ
             timeout=timeout
         )
 
-    except requests.exceptions.ConnectionError as exc:
-        # DEBUG: print(f"DEBUG: Fetching '{path}' from '{domain}' failed. exc[{type(exc)}]='{str(exc)}'")
-        instances.update_last_error(domain, exc)
-        raise exc
+    except requests.exceptions.ConnectionError as exception:
+        # DEBUG: print(f"DEBUG: Fetching '{path}' from '{domain}' failed. exception[{type(exception)}]='{str(exception)}'")
+        instances.update_last_error(domain, exception)
+        raise exception
 
     # DEBUG: print(f"DEBUG: response[]='{type(response)}' - EXXIT!")
     return response