From e270d1f0cc446a4ab8102a13b864c809dd4fe33e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 8 Jun 2023 16:54:09 +0200 Subject: [PATCH] Continued: - "get" should be used only for getters - removed variable "get_peers_url" which was used only once in code --- fba/fba.py | 25 +++++++++++-------------- fba/federation/gotosocial.py | 2 +- fba/federation/lemmy.py | 2 +- fba/federation/misskey.py | 2 +- fba/federation/peertube.py | 2 +- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/fba/fba.py b/fba/fba.py index 9a8b3d7..e52ddc3 100644 --- a/fba/fba.py +++ b/fba/fba.py @@ -63,9 +63,6 @@ api_headers = { "Content-Type": "application/json", } -# URL for fetching peers -get_peers_url = "/api/v1/instance/peers" - # Connect to database connection = sqlite3.connect("blocks.db") cursor = connection.cursor() @@ -106,7 +103,7 @@ def fetch_instances(domain: str, origin: str, software: str, script: str, path: instances.add(domain, origin, script, path) # DEBUG: print("DEBUG: Fetching instances for domain:", domain, software) - peerlist = get_peers(domain, software) + peerlist = fetch_peers(domain, software) if (peerlist is None): print("ERROR: Cannot fetch peers:", domain) @@ -343,7 +340,7 @@ def log_error(domain: str, response: requests.models.Response): # DEBUG: print("DEBUG: EXIT!") -def get_peers(domain: str, software: str) -> list: +def fetch_peers(domain: str, software: str) -> list: # DEBUG: print(f"DEBUG: domain({len(domain)})={domain},software={software} - CALLED!") if type(domain) != str: raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'") @@ -353,25 +350,25 @@ def get_peers(domain: str, software: str) -> list: raise ValueError(f"software[]={type(software)} is not 'str'") if software == "misskey": - # DEBUG: print(f"DEBUG: Invoking misskey.get_peers({domain}) ...") - return misskey.get_peers(domain) + # DEBUG: print(f"DEBUG: Invoking misskey.fetch_peers({domain}) ...") + return misskey.fetch_peers(domain) elif software == "lemmy": - # DEBUG: print(f"DEBUG: Invoking lemmy.get_peers({domain}) ...") - return lemmy.get_peers(domain) + # DEBUG: print(f"DEBUG: Invoking lemmy.fetch_peers({domain}) ...") + return lemmy.fetch_peers(domain) elif software == "peertube": - # DEBUG: print(f"DEBUG: Invoking peertube.get_peers({domain}) ...") - return peertube.get_peers(domain) + # DEBUG: print(f"DEBUG: Invoking peertube.fetch_peers({domain}) ...") + return peertube.fetch_peers(domain) - # DEBUG: print(f"DEBUG: Fetching get_peers_url='{get_peers_url}' from '{domain}',software='{software}' ...") + # DEBUG: print(f"DEBUG: Fetching peers from '{domain}',software='{software}' ...") peers = list() try: - response = get_response(domain, get_peers_url, api_headers, (config.get("connection_timeout"), config.get("read_timeout"))) + response = get_response(domain, "/api/v1/instance/peers", api_headers, (config.get("connection_timeout"), config.get("read_timeout"))) data = json_from_response(response) # DEBUG: print(f"DEBUG: response.ok={response.ok},response.status_code={response.status_code},data[]='{type(data)}'") if not response.ok or response.status_code >= 400: - # DEBUG: print(f"DEBUG: Was not able to fetch '{get_peers_url}', trying alternative ...") + # DEBUG: print(f"DEBUG: Was not able to fetch peers, trying alternative ...") response = get_response(domain, "/api/v3/site", api_headers, (config.get("connection_timeout"), config.get("read_timeout"))) data = json_from_response(response) diff --git a/fba/federation/gotosocial.py b/fba/federation/gotosocial.py index 00a367f..0b10756 100644 --- a/fba/federation/gotosocial.py +++ b/fba/federation/gotosocial.py @@ -40,7 +40,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): try: # Blocks - federation = fba.get_response(domain, f"{fba.get_peers_url}?filter=suspended", fba.api_headers, (config.get("connection_timeout"), config.get("read_timeout"))).json() + federation = fba.get_response(domain, f"{fba.fetch_peers_url}?filter=suspended", fba.api_headers, (config.get("connection_timeout"), config.get("read_timeout"))).json() if (federation == None): print("WARNING: No valid response:", domain); diff --git a/fba/federation/lemmy.py b/fba/federation/lemmy.py index 46b2b8e..8f7ce56 100644 --- a/fba/federation/lemmy.py +++ b/fba/federation/lemmy.py @@ -18,7 +18,7 @@ from fba import config from fba import fba from fba import instances -def get_peers(domain: str) -> list: +def fetch_peers(domain: str) -> list: # DEBUG: print(f"DEBUG: domain({len(domain)})={domain},software='lemmy' - CALLED!") if type(domain) != str: raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'") diff --git a/fba/federation/misskey.py b/fba/federation/misskey.py index a995b14..1428948 100644 --- a/fba/federation/misskey.py +++ b/fba/federation/misskey.py @@ -21,7 +21,7 @@ from fba import config from fba import fba from fba import instances -def get_peers(domain: str) -> list: +def fetch_peers(domain: str) -> list: # DEBUG: print(f"DEBUG: domain({len(domain)})={domain} - CALLED!") if type(domain) != str: raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'") diff --git a/fba/federation/peertube.py b/fba/federation/peertube.py index 8e839e3..da50cf3 100644 --- a/fba/federation/peertube.py +++ b/fba/federation/peertube.py @@ -18,7 +18,7 @@ from fba import config from fba import fba from fba import instances -def get_peers(domain: str) -> list: +def fetch_peers(domain: str) -> list: # DEBUG: print(f"DEBUG: domain({len(domain)})={domain},software='peertube' - CALLED!") if type(domain) != str: raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'") -- 2.39.5