From: Roland Häder Date: Wed, 21 Jun 2023 02:39:21 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9cb4c83ad47dba379e89f04b2eb862d30a76b710;p=fba.git Continued: - ops, fixed variable chaos --- diff --git a/fba/networks/friendica.py b/fba/networks/friendica.py index 20814a6..ffce628 100644 --- a/fba/networks/friendica.py +++ b/fba/networks/friendica.py @@ -32,8 +32,8 @@ def fetch_blocks(domain: str) -> dict: elif domain == "": raise ValueError("Parameter 'domain' is empty") - blocked = list() - blocklist = None + blocklist = list() + block_tag = None try: # DEBUG: print("DEBUG: Fetching friendica blocks from domain:", domain) @@ -48,18 +48,18 @@ def fetch_blocks(domain: str) -> dict: ) # DEBUG: print(f"DEBUG: doc[]='{type(doc)}'") - blocklist = doc.find(id="about_blocklist") + block_tag = doc.find(id="about_blocklist") except network.exceptions as exception: print(f"WARNING: Exception '{type(exception)}' during fetching instances (friendica) from domain='{domain}'") instances.set_last_error(domain, exception) return dict() # Prevents exceptions: - if blocklist is None: + if block_tag is None: # DEBUG: print("DEBUG: Instance has no block list:", domain) return dict() - table = blocklist.find("table") + table = block_tag.find("table") # DEBUG: print(f"DEBUG: table[]='{type(table)}'") if table.find("tbody"): @@ -71,7 +71,8 @@ def fetch_blocks(domain: str) -> dict: for line in rows: # DEBUG: print(f"DEBUG: line='{line}'") blocked = tidyup.domain(line.find_all("td")[0].text) - print(f"DEBUG: blocked='{blocked}'") + reason = tidyup.reason(line.find_all("td")[1].text) + # DEBUG: print(f"DEBUG: blocked='{blocked}',reason='{reason}'") if not validators.domain(blocked): print(f"WARNING: blocked='{blocked}' is not a valid domain - SKIPPED!") @@ -86,13 +87,14 @@ def fetch_blocks(domain: str) -> dict: # DEBUG: print(f"DEBUG: blocked='{blocked}' is blacklisted - SKIPPED!") continue - blocked.append({ + # DEBUG: print(f"DEBUG: Appending blocked='{blocked}',reason='{reason}'") + blocklist.append({ "domain": tidyup.domain(blocked), - "reason": tidyup.reason(line.find_all("td")[1].text) + "reason": tidyup.reason(reason) }) # DEBUG: print("DEBUG: Next!") # DEBUG: print("DEBUG: Returning blocklist() for domain:", domain, len(blocklist)) return { - "reject": blocked + "reject": blocklist }