From: Roland Häder Date: Sat, 18 Nov 2023 14:25:47 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=6bb7dacef9f9af3c54b5768dcb929d5a70d58a83;p=fba.git Continued: - lesser code block indenting --- diff --git a/fba/networks/peertube.py b/fba/networks/peertube.py index fd188d3..81c1dc8 100644 --- a/fba/networks/peertube.py +++ b/fba/networks/peertube.py @@ -31,12 +31,10 @@ def fetch_peers(domain: str) -> list: logger.debug("domain='%s' - CALLED!", domain) domain_helper.raise_on(domain) - logger.debug("domain='%s' is a PeerTube, fetching JSON ...", domain) + # Init variables peers = list() - start = 0 - - # No CSRF by default, you don't have to add network.api_headers by yourself here headers = tuple() + start = 0 try: logger.debug("Checking CSRF for domain='%s'", domain) @@ -60,38 +58,46 @@ def fetch_peers(domain: str) -> list: logger.debug("data[]='%s'", type(data)) if "error_message" not in data: + logger.warning("domain='%s' causes error during API query: '%s' - SKIPPED!", domain, data['error_message']) + break + elif "data" not in data["json"]: + logger.warning("domain='%s' has no 'data' element returned - SKIPPED!", domain) + break + else: logger.debug("Success, data[json]()=%d", len(data["json"])) instances.set_success(domain) - if "data" in data["json"]: - rows = data["json"]["data"] - - logger.debug("Found %d record(s).", len(rows)) - for record in rows: - logger.debug("record()=%d", len(record)) - for mode2 in ["follower", "following"]: - logger.debug("mode=%s,mode2='%s'", mode, mode2) - if mode2 in record and "host" in record[mode2] and record[mode2]["host"] != domain: - logger.debug("record[%s][host]='%s'", mode2, record[mode2]["host"]) - if not domain_helper.is_wanted(record[mode2]["host"]): - logger.debug("record[%s][host]='%s' is not wanted - SKIPPED!", mode2, record[mode2]["host"]) - continue - - logger.debug("Found mode2='%s',host='%s', adding ...", mode2, record[mode2]["host"]) - peers.append(record[mode2]["host"]) - - if len(rows) < 100: - logger.debug("Reached end of JSON response, domain='%s'", domain) - break - else: - logger.warning("domain='%s' has no 'data' element returned - SKIPPED!", domain) + rows = data["json"]["data"] + + logger.debug("Found %d record(s).", len(rows)) + for record in rows: + logger.debug("record()=%d", len(record)) + for mode2 in ["follower", "following"]: + logger.debug("mode=%s,mode2='%s'", mode, mode2) + if mode2 not in record: + logger.debug("Array record does not contain element mode2='%s' - SKIPPED", mode2) + continue + elif "host" not in record[mode2]: + logger.debug("record[%s] does not contain element 'host' - SKIPPED", mode2) + continue + elif record[mode2]["host"] == domain: + logger.debug("record[%s]='%s' matches domain='%s' - SKIPPED!", mode2, record[mode2]["hnost"], domain) + continue + + logger.debug("record[%s][host]='%s'", mode2, record[mode2]["host"]) + if not domain_helper.is_wanted(record[mode2]["host"]): + logger.debug("record[%s][host]='%s' is not wanted - SKIPPED!", mode2, record[mode2]["host"]) + continue + + logger.debug("Appending mode2='%s',host='%s' ...", mode2, record[mode2]["host"]) + peers.append(record[mode2]["host"]) + + if len(rows) < 100: + logger.debug("Reached end of JSON response, domain='%s'", domain) break # Continue with next row start = start + 100 - else: - logger.warning("domain='%s' causes error during API query: '%s' - SKIPPED!", domain, data['error_message']) - break logger.debug("peers[%s]()=%d - EXIT!", type(peers), len(peers)) return peers