elif software == "lemmy":
# DEBUG: print(f"DEBUG: domain='{domain}' is Lemmy, fetching JSON ...")
try:
- res = reqto.get(f"https://{domain}/api/v3/site", headers=api_headers, timeout=(config.get("connection_timeout"), config.get("read_timeout")))
+ res = get_response(domain, "/api/v3/site", api_headers, (config.get("connection_timeout"), config.get("read_timeout")))
data = json_from_response(res)
# DEBUG: print(f"DEBUG: domain='{domain}',mode='{mode}'")
while True:
try:
- res = reqto.get(f"https://{domain}/api/v1/server/{mode}?start={start}&count=100", headers=headers, timeout=(config.get("connection_timeout"), config.get("read_timeout")))
+ res = get_response(domain, "/api/v1/server/{mode}?start={start}&count=100", headers, (config.get("connection_timeout"), config.get("read_timeout")))
data = json_from_response(res)
# DEBUG: print(f"DEBUG: res.ok={res.ok},res.status_code='{res.status_code}',data[]='{type(data)}'")
# DEBUG: print(f"DEBUG: Fetching get_peers_url='{get_peers_url}' from '{domain}' ...")
try:
- res = reqto.get(f"https://{domain}{get_peers_url}", headers=api_headers, timeout=(config.get("connection_timeout"), config.get("read_timeout")))
+ res = get_response(domain, get_peers_url, api_headers, (config.get("connection_timeout"), config.get("read_timeout")))
data = json_from_response(res)
# DEBUG: print(f"DEBUG: res.ok={res.ok},res.status_code={res.status_code},data[]='{type(data)}'")
if not res.ok or res.status_code >= 400:
# DEBUG: print(f"DEBUG: Was not able to fetch '{get_peers_url}', trying alternative ...")
- res = reqto.get(f"https://{domain}/api/v3/site", headers=api_headers, timeout=(config.get("connection_timeout"), config.get("read_timeout")))
+ res = get_response(domain, "/api/v3/site", api_headers, (config.get("connection_timeout"), config.get("read_timeout")))
data = json_from_response(res)
# DEBUG: print(f"DEBUG: res.ok={res.ok},res.status_code={res.status_code},data[]='{type(data)}'")
data = {}
try:
- res = reqto.get(f"https://{domain}/.well-known/nodeinfo", headers=api_headers, timeout=(config.get("nodeinfo_connection_timeout"), config.get("nodeinfo_read_timeout")))
+ res = get_response(domain, "/.well-known/nodeinfo", api_headers, (config.get("nodeinfo_connection_timeout"), config.get("nodeinfo_read_timeout")))
data = json_from_response(res)
# DEBUG: print("DEBUG: domain,res.ok,data[]:", domain, res.ok, type(data))
try:
# DEBUG: print(f"DEBUG: Fetching path='{path}' from '{domain}' ...")
- res = reqto.get(f"https://{domain}{path}", headers=headers, timeout=(config.get("connection_timeout"), config.get("read_timeout")))
+ response = get_response(domain, path, headers, (config.get("connection_timeout"), config.get("read_timeout")))
# DEBUG: print("DEBUG: domain,res.ok,res.status_code,res.text[]:", domain, res.ok, res.status_code, type(res.text))
if res.ok and res.status_code < 300 and len(res.text) > 0:
try:
doc = bs4.BeautifulSoup(
- reqto.get(f"https://{domain}/about", headers=headers, timeout=(config.get("connection_timeout"), config.get("read_timeout"))).text,
+ get_response(domain, "/about", headers, (config.get("connection_timeout"), config.get("read_timeout"))).text,
"html.parser",
)
except BaseException as e:
try:
doc = bs4.BeautifulSoup(
- reqto.get(f"https://{domain}/friendica", headers=headers, timeout=(config.get("connection_timeout"), config.get("read_timeout"))).text,
+ get_response(domain, "/friendica", headers, (config.get("connection_timeout"), config.get("read_timeout"))).text,
"html.parser",
)
except BaseException as e:
# DEBUG: print(f"DEBUG: data[]={type(data)} - EXIT!")
return data
+
+def get_response(domain: str, path: str, headers: dict, timeout: list) -> requests.models.Response:
+ # DEBUG: print(f"DEBUG: domain='{domain}',path='{path}',headers()={len(headers)},timeout={timeout} - CALLED!")
+ if type(domain) != str:
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
+ elif type(path) != str:
+ raise ValueError(f"Parameter path[]='{type(path)}' is not 'str'")
+
+ # DEBUG: print(f"DEBUG: Sending request to '{domain}{path}' ...")
+ response = reqto.get(f"https://{domain}{path}", headers=headers, timeout=timeout);
+
+ # DEBUG: print(f"DEBUG: response[]='{type(response)}' - EXXIT!")
+ return response
# handling CSRF, I've saw at least one server requiring it to access the endpoint
# DEBUG: print("DEBUG: Fetching meta:", blocker)
meta = bs4.BeautifulSoup(
- reqto.get(f"https://{blocker}/", headers=fba.headers, timeout=(config.get("connection_timeout"), config.get("read_timeout"))).text,
+ fba.get_response(blocker, "/", fba.headers, (config.get("connection_timeout"), config.get("read_timeout"))).text,
"html.parser",
)
try:
reqheaders = fba.api_headers
# DEBUG: print("DEBUG: Querying API domain_blocks:", blocker)
- blocks = reqto.get(f"https://{blocker}/api/v1/instance/domain_blocks", headers=reqheaders, timeout=(config.get("connection_timeout"), config.get("read_timeout"))).json()
+ blocks = fba.get_response(blocker, "/api/v1/instance/domain_blocks", reqheaders, (config.get("connection_timeout"), config.get("read_timeout"))).json()
print(f"INFO: Checking {len(blocks)} entries from blocker='{blocker}',software='{software}' ...")
for block in blocks:
print("INFO: blocker:", blocker)
try:
# Blocks
- federation = reqto.get(f"https://{blocker}{fba.get_peers_url}?filter=suspended", headers=fba.api_headers, timeout=(config.get("connection_timeout"), config.get("read_timeout"))).json()
+ federation = fba.get_response(blocker, "{fba.get_peers_url}?filter=suspended", fba.api_headers, (config.get("connection_timeout"), config.get("read_timeout"))).json()
if (federation == None):
print("WARNING: No valid response:", blocker);