X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=fba%2Fnetworks%2Flemmy.py;h=bfe1e805f0eed78685d3fa7669de0bb966aca2ac;hb=7ce34f60c519ff20cc76b2030a91a0cefde3062b;hp=ebbe9a1bb877d9cd1520307793d4050e8effb0a3;hpb=af0f602ef1f71e75b7ee8fbb60d4b213ac766b59;p=fba.git diff --git a/fba/networks/lemmy.py b/fba/networks/lemmy.py index ebbe9a1..bfe1e80 100644 --- a/fba/networks/lemmy.py +++ b/fba/networks/lemmy.py @@ -19,6 +19,7 @@ import logging import bs4 +from fba.helpers import blacklist from fba.helpers import config from fba.helpers import domain as domain_helper from fba.helpers import tidyup @@ -33,10 +34,47 @@ logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) #logger.setLevel(logging.DEBUG) +# Lemmy translations +translations = [ + "Blocked Instances".lower(), + "Instàncies bloquejades".lower(), + "Blocáilte Ásc".lower(), + "封锁实例".lower(), + "Blokované instance".lower(), + "Geblokkeerde instanties".lower(), + "Blockerade instanser".lower(), + "Instàncias blocadas".lower(), + "Istanze bloccate".lower(), + "Instances bloquées".lower(), + "Letiltott példányok".lower(), + "Instancias bloqueadas".lower(), + "Blokeatuta dauden instantziak".lower(), + "차단된 인스턴스".lower(), + "Peladen Yang Diblokir".lower(), + "Blokerede servere".lower(), + "Blokitaj nodoj".lower(), + "Блокирани Инстанции".lower(), + "Blockierte Instanzen".lower(), + "Estetyt instanssit".lower(), + "Instâncias bloqueadas".lower(), + "Zablokowane instancje".lower(), + "Blokované inštancie".lower(), + "المثلاء المحجوبون".lower(), + "Užblokuoti serveriai".lower(), + "ブロックしたインスタンス".lower(), + "Блокированные Инстансы".lower(), + "Αποκλεισμένοι διακομιστές".lower(), + "封鎖站台".lower(), + "Instâncias bloqueadas".lower(), +] + def fetch_peers(domain: str, origin: str) -> list: logger.debug("domain='%s',origin='%s' - CALLED!", domain, origin) domain_helper.raise_on(domain) + if blacklist.is_blacklisted(domain): + raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + peers = list() # No CSRF by default, you don't have to add network.api_headers by yourself here @@ -87,42 +125,11 @@ def fetch_blocks(domain: str) -> list: logger.debug("domain='%s - CALLED!", domain) domain_helper.raise_on(domain) - if not instances.is_registered(domain): + if blacklist.is_blacklisted(domain): + raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + elif not instances.is_registered(domain): raise Exception(f"domain='{domain}' is not registered but function is invoked.") - translations = [ - "Blocked Instances".lower(), - "Instàncies bloquejades".lower(), - "Blocáilte Ásc".lower(), - "封锁实例".lower(), - "Blokované instance".lower(), - "Geblokkeerde instanties".lower(), - "Blockerade instanser".lower(), - "Instàncias blocadas".lower(), - "Istanze bloccate".lower(), - "Instances bloquées".lower(), - "Letiltott példányok".lower(), - "Instancias bloqueadas".lower(), - "Blokeatuta dauden instantziak".lower(), - "차단된 인스턴스".lower(), - "Peladen Yang Diblokir".lower(), - "Blokerede servere".lower(), - "Blokitaj nodoj".lower(), - "Блокирани Инстанции".lower(), - "Blockierte Instanzen".lower(), - "Estetyt instanssit".lower(), - "Instâncias bloqueadas".lower(), - "Zablokowane instancje".lower(), - "Blokované inštancie".lower(), - "المثلاء المحجوبون".lower(), - "Užblokuoti serveriai".lower(), - "ブロックしたインスタンス".lower(), - "Блокированные Инстансы".lower(), - "Αποκλεισμένοι διακομιστές".lower(), - "封鎖站台".lower(), - "Instâncias bloqueadas".lower(), - ] - blocklist = list() try: @@ -157,7 +164,7 @@ def fetch_blocks(domain: str) -> list: content = str(header.contents[0]) logger.debug("content[%s]='%s' - AFTER!", type(content), content) - if content is None: + if content is None or content == "": logger.debug("domain='%s' has returned empty header='%s' - SKIPPED!", domain, header) continue elif not isinstance(content, str): @@ -232,6 +239,9 @@ def fetch_instances(domain: str, origin: str) -> list: logger.debug("domain='%s',origin='%s' - CALLED!", domain, origin) domain_helper.raise_on(domain) + if blacklist.is_blacklisted(domain): + raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + peers = list() try: