From e795feb5e4a8239d45754dd3c053e0c7dcec1355 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 21 Jun 2023 19:44:35 +0200 Subject: [PATCH] Continued: - directly imported format_datetime to keep loading time short - fixed syntax errors --- api.py | 11 +++++------ fba/commands.py | 2 +- fba/http/federation.py | 8 ++++---- fba/networks/friendica.py | 2 +- fba/networks/lemmy.py | 2 +- fba/networks/mastodon.py | 4 ++-- fba/networks/pleroma.py | 8 ++++---- fba/utils.py | 2 +- 8 files changed, 19 insertions(+), 20 deletions(-) diff --git a/api.py b/api.py index ea35303..4b4b4da 100644 --- a/api.py +++ b/api.py @@ -14,11 +14,10 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from datetime import datetime -from email import utils - import re +from datetime import datetime +from email.utils import format_datetime from fastapi import Request, HTTPException, Query from fastapi.responses import JSONResponse from fastapi.responses import PlainTextResponse @@ -285,13 +284,13 @@ def rss(request: Request, domain: str = None): "blocked" : row[1], "block_level": row[2], "reason" : "Provided reason: '" + row[3] + "'" if row[3] is not None and row[3] != "" else "No reason provided.", - "first_seen" : utils.format_datetime(datetime.fromtimestamp(row[4])), - "last_seen" : utils.format_datetime(datetime.fromtimestamp(row[5])), + "first_seen" : format_datetime(datetime.fromtimestamp(row[4])), + "last_seen" : format_datetime(datetime.fromtimestamp(row[5])), }) return templates.TemplateResponse("rss.xml", { "request" : request, - "timestamp": utils.format_datetime(datetime.now()), + "timestamp": format_datetime(datetime.now()), "domain" : domain, "hostname" : config.get("hostname"), "blocks" : blocklist diff --git a/fba/commands.py b/fba/commands.py index 9ba1ff7..d1cf4c5 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -358,7 +358,7 @@ def fetch_observer(args: argparse.Namespace): domain = item.decode_contents() logger.debug("domain='%s'", domain) - if not utils.is_domain_wanted(domain) + if not utils.is_domain_wanted(domain): logger.debug("domain='%s' is not wanted - SKIPPED!", domain) continue elif instances.is_registered(domain): diff --git a/fba/http/federation.py b/fba/http/federation.py index 5f6616d..7968384 100644 --- a/fba/http/federation.py +++ b/fba/http/federation.py @@ -124,7 +124,7 @@ def fetch_instances(domain: str, origin: str, software: str, command: str, path: if instance == "": logger.warning(f"Empty instance after tidyup.domain(), domain='{domain}'") continue - elif not utils.is_domain_wanted((instance): + elif not utils.is_domain_wanted(instance): logger.debug("instance='%s' is not wanted - SKIPPED!", instance) continue elif instance.find("/profile/") > 0 or instance.find("/users/") > 0: @@ -354,7 +354,7 @@ def fetch_wellknown_nodeinfo(domain: str) -> dict: url = f"https://{domain}{url}" components = urlparse(url) - if not utils.is_domain_wanted((components.netloc): + if not utils.is_domain_wanted(components.netloc): logger.debug("components.netloc='%s' is not wanted - SKIPPED!", components.netloc) continue @@ -582,7 +582,7 @@ def find_domains(tag: bs4.element.Tag) -> list: logger.debug("domain='%s',reason='%s'", domain, reason) - if not utils.is_domain_wanted((domain): + if not utils.is_domain_wanted(domain): logger.debug("domain='%s' is blacklisted - SKIPPED!", domain) continue elif domain == "gab.com/.ai, develop.gab.com": @@ -638,7 +638,7 @@ def add_peers(rows: dict) -> list: raise ValueError(f"peer[]='{type(peer)}' is not supported,key='{key}'") logger.debug(f"peer='{peer}' - AFTER!") - if not utils.is_domain_wanted((peer): + if not utils.is_domain_wanted(peer): logger.debug("peer='%s' is not wanted - SKIPPED!", peer) continue diff --git a/fba/networks/friendica.py b/fba/networks/friendica.py index 8fca330..3714119 100644 --- a/fba/networks/friendica.py +++ b/fba/networks/friendica.py @@ -89,7 +89,7 @@ def fetch_blocks(domain: str) -> dict: reason = tidyup.reason(line.find_all("td")[1].text) logger.debug(f"blocked='{blocked}',reason='{reason}'") - if not utils.is_domain_wanted((blocked): + if not utils.is_domain_wanted(blocked): logger.debug("blocked='%s' is not wanted - SKIPPED!", blocked) continue diff --git a/fba/networks/lemmy.py b/fba/networks/lemmy.py index c575386..12c40d3 100644 --- a/fba/networks/lemmy.py +++ b/fba/networks/lemmy.py @@ -204,7 +204,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): blocked = tidyup.domain(tag.contents[0]) logger.debug(f"blocked='{blocked}'") - if not utils.is_domain_wanted((blocked): + if not utils.is_domain_wanted(blocked): logger.debug("blocked='%s' is not wanted - SKIPPED!", blocked) continue elif not instances.is_registered(blocked): diff --git a/fba/networks/mastodon.py b/fba/networks/mastodon.py index 966477c..ce662da 100644 --- a/fba/networks/mastodon.py +++ b/fba/networks/mastodon.py @@ -301,7 +301,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): nodeinfo_url = row[2] logger.debug("Looking up instance by domain:", blocked) - if not utils.is_domain_wanted((blocked): + if not utils.is_domain_wanted(blocked): logger.debug("blocked='%s' is not wanted - SKIPPED!", blocked) continue elif not instances.is_registered(blocked): @@ -309,7 +309,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): instances.add(blocked, domain, inspect.currentframe().f_code.co_name, nodeinfo_url) logger.debug("Looking up instance by domain:", blocked) - if not utils.is_domain_wanted((blocked): + if not utils.is_domain_wanted(blocked): logger.debug("blocked='%s' is not wanted - SKIPPED!", blocked) continue elif not instances.is_registered(blocked): diff --git a/fba/networks/pleroma.py b/fba/networks/pleroma.py index 8ef7a06..7899906 100644 --- a/fba/networks/pleroma.py +++ b/fba/networks/pleroma.py @@ -220,7 +220,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): nodeinfo_url = row[2] logger.debug(f"blocked='{blocked}'") - if not utils.is_domain_wanted((blocked): + if not utils.is_domain_wanted(blocked): logger.debug("blocked='%s' is not wanted - SKIPPED!", blocked) continue elif not instances.is_registered(blocked): @@ -321,7 +321,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): nodeinfo_url = row[2] logger.debug(f"blocked='{blocked}'") - if not utils.is_domain_wanted((blocked): + if not utils.is_domain_wanted(blocked): logger.debug("blocked='%s' is not wanted - SKIPPED!", blocked) continue elif not instances.is_registered(blocked): @@ -390,7 +390,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): nodeinfo_url = row[2] logger.debug(f"blocked='{blocked}'") - if not utils.is_domain_wanted((blocked): + if not utils.is_domain_wanted(blocked): logger.debug("blocked='%s' is not wanted - SKIPPED!", blocked) continue elif not instances.is_registered(blocked): @@ -460,7 +460,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): nodeinfo_url = row[2] logger.debug(f"blocked='{blocked}'") - if not utils.is_domain_wanted((blocked): + if not utils.is_domain_wanted(blocked): logger.warning("blocked='%s' is not wanted - SKIPPED!", blocked) continue elif not instances.is_registered(blocked): diff --git a/fba/utils.py b/fba/utils.py index 46fa37e..7850b39 100644 --- a/fba/utils.py +++ b/fba/utils.py @@ -133,7 +133,7 @@ def process_domain(domain: str, blocker: str, command: str) -> bool: logger.debug(f"domain='{domain}' de-obscured to '{row[0]}'") domain = row[0] - if not is_domain_wanted(domain) + if not is_domain_wanted(domain): logger.debug("domain='%s' is not wanted - SKIPPED!", domain) return False elif instances.is_recent(domain): -- 2.39.5