from fba.http import federation
from fba.http import network
-from fba.models import apis
from fba.models import blocks
from fba.models import instances
+from fba.models import sources
from fba.networks import friendica
from fba.networks import lemmy
def fetch_pixelfed_api(args: argparse.Namespace) -> int:
logger.debug("args[]='%s' - CALLED!", type(args))
- # No CSRF by default, you don't have to add network.api_headers by yourself here
+ # No CSRF by default, you don't have to add network.source_headers by yourself here
headers = tuple()
- api_domain = "pixelfed.org"
+ source_domain = "pixelfed.org"
- if apis.is_recent(api_domain):
- logger.info("API from api_domain='%s' has recently being accessed - EXIT!", api_domain)
+ if sources.is_recent(source_domain):
+ logger.info("API from source_domain='%s' has recently being accessed - EXIT!", source_domain)
return 0
else:
- logger.debug("api_domain='%s' has not been recently used, marking ...", api_domain)
- apis.update(api_domain)
+ logger.debug("source_domain='%s' has not been recently used, marking ...", source_domain)
+ sources.update(source_domain)
try:
- logger.debug("Checking CSRF from api_domain='%s' ...", api_domain)
- headers = csrf.determine(api_domain, dict())
+ logger.debug("Checking CSRF from source_domain='%s' ...", source_domain)
+ headers = csrf.determine(source_domain, dict())
except network.exceptions as exception:
logger.warning("Exception '%s' during checking CSRF (fetch_peers,%s) - EXIT!", type(exception), __name__)
return list()
try:
logger.debug("Fetching JSON from pixelfed.org API, headers()=%d ...", len(headers))
fetched = network.get_json_api(
- api_domain,
+ source_domain,
"/api/v1/servers/all.json?scope=All&country=all&language=all",
headers,
(config.get("connection_timeout"), config.get("read_timeout"))
logger.debug("Invoking locking.acquire() ...")
locking.acquire()
- api_domain = "gql.apis.bka.li"
- if apis.is_recent(api_domain):
- logger.info("API from api_domain='%s' has recently being accessed - EXIT!", api_domain)
+ source_domain = "gql.sources.bka.li"
+ if sources.is_recent(source_domain):
+ logger.info("API from source_domain='%s' has recently being accessed - EXIT!", source_domain)
return 0
else:
- logger.debug("api_domain='%s' has not been recently used, marking ...", api_domain)
- apis.update(api_domain)
+ logger.debug("source_domain='%s' has not been recently used, marking ...", source_domain)
+ sources.update(source_domain)
domains = list()
try:
- logger.info("Fetching domainlist from api_domain='%s' ...", api_domain)
+ logger.info("Fetching domainlist from source_domain='%s' ...", source_domain)
fetched = network.post_json_api(
- api_domain,
+ source_domain,
"/v1/graphql",
json.dumps({
"query": "query domainlist {nodeinfo(order_by: {domain: asc}) {domain}}"
logger.debug("fetched[]='%s'", type(fetched))
if "error_message" in fetched:
- logger.warning("post_json_api() for 'gql.apis.bka.li' returned error message='%s", fetched["error_message"])
+ logger.warning("post_json_api() for 'gql.sources.bka.li' returned error message='%s", fetched["error_message"])
return 100
elif isinstance(fetched["json"], dict) and "error" in fetched["json"] and "message" in fetched["json"]["error"]:
logger.warning("post_json_api() returned error: '%s", fetched["error"]["message"])
logger.debug("Invoking locking.acquire() ...")
locking.acquire()
- api_domain = "fediverse.observer"
- if apis.is_recent(api_domain):
- logger.info("API from api_domain='%s' has recently being accessed - EXIT!", api_domain)
+ source_domain = "fediverse.observer"
+ if sources.is_recent(source_domain):
+ logger.info("API from source_domain='%s' has recently being accessed - EXIT!", source_domain)
return 0
else:
- logger.debug("api_domain='%s' has not been recently used, marking ...", api_domain)
- apis.update(api_domain)
+ logger.debug("source_domain='%s' has not been recently used, marking ...", source_domain)
+ sources.update(source_domain)
types = list()
if args.software is None:
logger.info("Fetching software list ...")
raw = utils.fetch_url(
- f"https://{api_domain}",
+ f"https://{source_domain}",
network.web_headers,
(config.get("connection_timeout"), config.get("read_timeout"))
).text
try:
logger.debug("Fetching table data for software='%s' ...", software)
raw = utils.fetch_url(
- f"https://{api_domain}/app/views/tabledata.php?software={software}",
+ f"https://{source_domain}/app/views/tabledata.php?software={software}",
network.web_headers,
(config.get("connection_timeout"), config.get("read_timeout"))
).text
doc = bs4.BeautifulSoup(raw, features="html.parser")
logger.debug("doc[]='%s'", type(doc))
except network.exceptions as exception:
- logger.warning("Cannot fetch software='%s' from api_domain='%s': '%s'", software, api_domain, type(exception))
+ logger.warning("Cannot fetch software='%s' from source_domain='%s': '%s'", software, source_domain, type(exception))
continue
items = doc.findAll("a", {"class": "url"})
logger.debug("Invoking locking.acquire() ...")
locking.acquire()
- api_domain = "wiki.todon.eu"
- if apis.is_recent(api_domain):
- logger.info("API from api_domain='%s' has recently being accessed - EXIT!", api_domain)
+ source_domain = "wiki.todon.eu"
+ if sources.is_recent(source_domain):
+ logger.info("API from source_domain='%s' has recently being accessed - EXIT!", source_domain)
return 0
else:
- logger.debug("api_domain='%s' has not been recently used, marking ...", api_domain)
- apis.update(api_domain)
+ logger.debug("source_domain='%s' has not been recently used, marking ...", source_domain)
+ sources.update(source_domain)
blocklist = {
"silenced": list(),
"reject": list(),
}
- raw = utils.fetch_url(f"https://{api_domain}/todon/domainblocks", network.web_headers, (config.get("connection_timeout"), config.get("read_timeout"))).text
+ raw = utils.fetch_url(f"https://{source_domain}/todon/domainblocks", network.web_headers, (config.get("connection_timeout"), config.get("read_timeout"))).text
logger.debug("raw()=%d,raw[]='%s'", len(raw), type(raw))
doc = bs4.BeautifulSoup(raw, "html.parser")
"reject" : list(),
}
- api_domain = "raw.githubusercontent.com"
- if apis.is_recent(api_domain):
- logger.info("API from api_domain='%s' has recently being accessed - EXIT!", api_domain)
+ source_domain = "raw.githubusercontent.com"
+ if sources.is_recent(source_domain):
+ logger.info("API from source_domain='%s' has recently being accessed - EXIT!", source_domain)
return 0
else:
- logger.debug("api_domain='%s' has not been recently used, marking ...", api_domain)
- apis.update(api_domain)
+ logger.debug("source_domain='%s' has not been recently used, marking ...", source_domain)
+ sources.update(source_domain)
- raw = utils.fetch_url(f"https://{api_domain}/chaossocial/meta/master/federation.md", network.web_headers, (config.get("connection_timeout"), config.get("read_timeout"))).text
+ raw = utils.fetch_url(f"https://{source_domain}/chaossocial/meta/master/federation.md", network.web_headers, (config.get("connection_timeout"), config.get("read_timeout"))).text
logger.debug("raw()=%d,raw[]='%s'", len(raw), type(raw))
doc = bs4.BeautifulSoup(markdown.markdown(raw, extensions=extensions), features="html.parser")
components = urlparse(args.feed)
- if apis.is_recent(components.netloc):
+ if sources.is_recent(components.netloc):
logger.info("API from components.netloc='%s' has recently being accessed - EXIT!", components.netloc)
return 0
else:
logger.debug("components.netloc='%s' has not been recently used, marking ...", components.netloc)
- apis.update(components.netloc)
+ sources.update(components.netloc)
logger.info("Fetch FBA-specific RSS args.feed='%s' ...", args.feed)
response = utils.fetch_url(args.feed, network.web_headers, (config.get("connection_timeout"), config.get("read_timeout")))
logger.debug("Invoking locking.acquire() ...")
locking.acquire()
- api_domain = "ryana.agency"
- if apis.is_recent(api_domain):
- logger.info("API from api_domain='%s' has recently being accessed - EXIT!", api_domain)
+ source_domain = "ryana.agency"
+ if sources.is_recent(source_domain):
+ logger.info("API from source_domain='%s' has recently being accessed - EXIT!", source_domain)
return 0
else:
- logger.debug("api_domain='%s' has not been recently used, marking ...", api_domain)
- apis.update(api_domain)
+ logger.debug("source_domain='%s' has not been recently used, marking ...", source_domain)
+ sources.update(source_domain)
- feed = f"https://{api_domain}/users/fba/feed.atom"
+ feed = f"https://{source_domain}/users/fba/feed.atom"
domains = list()
logger.debug("domain='%s'", domain)
try:
logger.info("Fetching instances from domain='%s' ...", domain)
- federation.fetch_instances(domain, api_domain, None, inspect.currentframe().f_code.co_name)
+ federation.fetch_instances(domain, source_domain, None, inspect.currentframe().f_code.co_name)
except network.exceptions as exception:
logger.warning("Exception '%s' during fetching instances (fetch_fbabot_atom) from domain='%s'", type(exception), domain)
instances.set_last_error(domain, exception)
logger.debug("Invoking locking.acquire() ...")
locking.acquire()
- api_domain = "codeberg.org"
- if apis.is_recent(api_domain):
- logger.info("API from api_domain='%s' has recently being accessed - EXIT!", api_domain)
+ source_domain = "codeberg.org"
+ if sources.is_recent(source_domain):
+ logger.info("API from source_domain='%s' has recently being accessed - EXIT!", source_domain)
return 0
else:
- logger.debug("api_domain='%s' has not been recently used, marking ...", api_domain)
- apis.update(api_domain)
+ logger.debug("source_domain='%s' has not been recently used, marking ...", source_domain)
+ sources.update(source_domain)
# Base URL
- base_url = f"https://{api_domain}/oliphant/blocklists/raw/branch/main/blocklists"
+ base_url = f"https://{source_domain}/oliphant/blocklists/raw/branch/main/blocklists"
# URLs to fetch
blocklists = (
logger.debug("Invoking locking.acquire() ...")
locking.acquire()
- api_domain = "fedipact.online"
- if apis.is_recent(api_domain):
- logger.info("API from api_domain='%s' has recently being accessed - EXIT!", api_domain)
+ source_domain = "fedipact.online"
+ if sources.is_recent(source_domain):
+ logger.info("API from source_domain='%s' has recently being accessed - EXIT!", source_domain)
return 0
else:
- logger.debug("api_domain='%s' has not been recently used, marking ...", api_domain)
- apis.update(api_domain)
+ logger.debug("source_domain='%s' has not been recently used, marking ...", source_domain)
+ sources.update(source_domain)
response = utils.fetch_url(
- f"https://{api_domain}",
+ f"https://{source_domain}",
network.web_headers,
(config.get("connection_timeout"), config.get("read_timeout"))
)
logger.debug("Invoking locking.acquire() ...")
locking.acquire()
- api_domain = "joinfediverse.wiki"
- if apis.is_recent(api_domain):
- logger.info("API from api_domain='%s' has recently being accessed - EXIT!", api_domain)
+ source_domain = "joinfediverse.wiki"
+ if sources.is_recent(source_domain):
+ logger.info("API from source_domain='%s' has recently being accessed - EXIT!", source_domain)
return 0
else:
- logger.debug("api_domain='%s' has not been recently used, marking ...", api_domain)
- apis.update(api_domain)
+ logger.debug("source_domain='%s' has not been recently used, marking ...", source_domain)
+ sources.update(source_domain)
raw = utils.fetch_url(
- f"https://{api_domain}/FediBlock",
+ f"https://{source_domain}/FediBlock",
network.web_headers,
(config.get("connection_timeout"), config.get("read_timeout"))
).text
logger.debug("Invoking locking.acquire() ...")
locking.acquire()
- api_domain = "demo.fedilist.com"
- if apis.is_recent(api_domain):
- logger.info("API from api_domain='%s' has recently being accessed - EXIT!", api_domain)
+ source_domain = "demo.fedilist.com"
+ if sources.is_recent(source_domain):
+ logger.info("API from source_domain='%s' has recently being accessed - EXIT!", source_domain)
return 0
else:
- logger.debug("api_domain='%s' has not been recently used, marking ...", api_domain)
- apis.update(api_domain)
+ logger.debug("source_domain='%s' has not been recently used, marking ...", source_domain)
+ sources.update(source_domain)
- url = f"http://{api_domain}/instance/csv?onion=not"
+ url = f"http://{source_domain}/instance/csv?onion=not"
if args.software is not None and args.software != "":
logger.debug("args.software='%s'", args.software)
- url = f"http://{api_domain}/instance/csv?software={args.software}&onion=not"
+ url = f"http://{source_domain}/instance/csv?software={args.software}&onion=not"
logger.info("Fetching url='%s' ...", url)
response = reqto.get(
logger.debug("Invoking locking.acquire() ...")
locking.acquire()
- api_domain = "instances.social"
+ source_domain = "instances.social"
if config.get("instances_social_api_key") == "":
logger.error("API key not set. Please set in your config.json file.")
return 1
- elif apis.is_recent(api_domain):
- logger.info("API from api_domain='%s' has recently being accessed - EXIT!", api_domain)
+ elif sources.is_recent(source_domain):
+ logger.info("API from source_domain='%s' has recently being accessed - EXIT!", source_domain)
return 0
else:
- logger.debug("api_domain='%s' has not been recently used, marking ...", api_domain)
- apis.update(api_domain)
+ logger.debug("source_domain='%s' has not been recently used, marking ...", source_domain)
+ sources.update(source_domain)
headers = {
"Authorization": f"Bearer {config.get('instances_social_api_key')}",
}
fetched = network.get_json_api(
- api_domain,
+ source_domain,
"/api/1.0/instances/list?count=0&sort_by=name",
headers,
(config.get("connection_timeout"), config.get("read_timeout"))
continue
logger.info("Fetching instances from domain='%s'", domain)
- federation.fetch_instances(domain, api_domain, None, inspect.currentframe().f_code.co_name)
+ federation.fetch_instances(domain, source_domain, None, inspect.currentframe().f_code.co_name)
logger.debug("Success! - EXIT!")
return 0