import argparse
import atoma
import bs4
+import csv
import inspect
import itertools
import json
try:
print(f"INFO: Fetch FBA-specific RSS args.feed='{args.feed}' ...")
- response = fba.get_url(args.feed, fba.headers, (config.get("connection_timeout"), config.get("read_timeout")))
+ response = fba.fetch_url(args.feed, fba.headers, (config.get("connection_timeout"), config.get("read_timeout")))
# DEBUG: print(f"DEBUG: response.ok={response.ok},response.status_code='{response.status_code}',response.text()={len(response.text)}")
if response.ok and response.status_code < 300 and len(response.text) > 0:
domains = list()
try:
print(f"INFO: Fetching ATOM feed='{feed}' from FBA bot account ...")
- response = fba.get_url(feed, fba.headers, (config.get("connection_timeout"), config.get("read_timeout")))
+ response = fba.fetch_url(feed, fba.headers, (config.get("connection_timeout"), config.get("read_timeout")))
# DEBUG: print(f"DEBUG: response.ok={response.ok},response.status_code='{response.status_code}',response.text()={len(response.text)}")
if response.ok and response.status_code < 300 and len(response.text) > 0:
fba.fetch_instances(row[0], row[1], row[2], inspect.currentframe().f_code.co_name, row[3])
# DEBUG: print("DEBUG: EXIT!")
+
+def fetch_federater(args: argparse.Namespace):
+ # DEBUG: print(f"DEBUG: args[]={type(args)} - CALLED!")
+ boot.acquire_lock()
+
+ # Fetch this URL
+ response = fba.fetch_url("https://github.com/federater/blocks_recommended/raw/main/federater.csv", fba.headers, (config.get("connection_timeout"), config.get("read_timeout")))
+ # DEBUG: print(f"DEBUG: response[]='{type(response)}'")
+ if response.ok and response.content != "":
+ # DEBUG: print(f"DEBUG: Fetched {len(response.content)} Bytes, parsing CSV ...")
+ #print(f"DEBUG: response.content={response.content}")
+ reader = csv.DictReader(response.content.decode('utf-8').splitlines(), dialect='unix')
+ #, fieldnames='domain,severity,reject_media,reject_reports,public_comment,obfuscate'
+ # DEBUG: print(f"DEBUG: reader[]={type(reader)}")
+ for row in reader:
+ if not validators.domain(row["#domain"]):
+ print(f"WARNING: domain='{row['#domain']}' is not a valid domain - skipped!")
+ continue
+ elif blacklist.is_blacklisted(row["#domain"]):
+ print(f"WARNING: domain='{row['#domain']}' is blacklisted - skipped!")
+ continue
+ elif instances.is_registered(row["#domain"]):
+ # DEBUG: print(f"DEBUG: domain='{row['#domain']}' is already registered - skipped!")
+ continue
+
+ print(f"INFO: Fetching instances for instane='{row['#domain']}' ...")
+ fba.fetch_instances(row["#domain"], 'github.com', None, inspect.currentframe().f_code.co_name)
+
+ # DEBUG: print("DEBUG: EXIT!")
raise ValueError(f"Parameter 'domain' is empty")
elif type(origin) != str and origin != None:
raise ValueError(f"Parameter origin[]={type(origin)} is not 'str'")
+ elif software == None:
+ print(f"DEBUG: software for domain='{domain}' is not set, determining ...")
+ software = determine_software(domain, path)
+ print(f"DEBUG: Determined software='{software}' for domain='{domain}'")
+ elif type(software) != str:
+ raise ValueError(f"Parameter software[]={type(software)} is not 'str'")
elif type(script) != str:
raise ValueError(f"Parameter script[]={type(script)} is not 'str'")
elif domain == "":
# DEBUG: print("DEBUG: rel,href:", link["rel"], link["href"])
if link["rel"] in nodeinfo_identifier:
# DEBUG: print("DEBUG: Fetching nodeinfo from:", link["href"])
- response = get_url(link["href"], api_headers, (config.get("connection_timeout"), config.get("read_timeout")))
+ response = fetch_url(link["href"], api_headers, (config.get("connection_timeout"), config.get("read_timeout")))
data = json_from_response(response)
# DEBUG: print("DEBUG: href,response.ok,response.status_code:", link["href"], response.ok, response.status_code)
# DEBUG: print(f"DEBUG: domains()={len(domains)} - EXIT!")
return domains
-def get_url(url: str, headers: dict, timeout: list) -> requests.models.Response:
+def fetch_url(url: str, headers: dict, timeout: list) -> requests.models.Response:
# DEBUG: print(f"DEBUG: url='{url}',headers()={len(headers)},timeout={timeout} - CALLED!")
if type(url) != str:
raise ValueError(f"Parameter url[]='{type(url)}' is not 'str'")