From: Roland Häder Date: Fri, 2 Jun 2023 21:01:20 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9570b6a381993adccd031ca8dc6a7d6e95e64c5d;p=fba.git Continued: - added Python script to fetch domains from bka.la (thank you to Kromonos) --- diff --git a/fetch_bkali.py b/fetch_bkali.py new file mode 100755 index 0000000..f09612d --- /dev/null +++ b/fetch_bkali.py @@ -0,0 +1,59 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +# Fedi API Block - An aggregator for fetching blocking data from fediverse nodes +# Copyright (C) 2023 Free Software Foundation +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import json +import sys +import validators +import fba + +domains = list() +try: + fetched = fba.post_json_api("gql.api.bka.li", "/v1/graphql", json.dumps({ + "query": "query domainlist {nodeinfo(order_by: {domain: asc}) {domain}}" + })) + + # DEBUG: print(f"DEBUG: fetched({len(fetched)})[]='{type(fetched)}'") + if len(fetched) > 0 and "data" in fetched and "nodeinfo" in fetched["data"]: + for entry in fetched["data"]["nodeinfo"]: + # DEBUG: print(f"DEBUG: entry['{type(entry)}']='{entry}'") + if not "domain" in entry: + print(f"WARNING: entry does not contain 'domain' - SKIPPED!") + continue + elif not validators.domain(entry["domain"]): + print(f"WARNING: domain='{entry['domain']}' is {entry['domain']}' is not a valid domain - SKIPPED!") + continue + elif fba.is_blacklisted(entry["domain"]): + # DEBUG: print(f"DEBUG: domain='blacklisted - SKIPPED!") + continue + + domains.append(entry["domain"]) + +except BaseException as e: + print(f"ERROR: Cannot fetch graphql,exception[{type(e)}]:'{str(e)}'") + sys.exit(255) + +# Show domains +# DEBUG: print(f"DEBUG: domains()={len(domains)}") +if len(domains) > 0: + print(f"INFO: Adding {len(domains)} new instances ...") + for domain in domains: + print(f"INFO: Fetching instances from domain='{domain}' ...") + fba.fetch_instances(domain, None, None, sys.argv[0]) + +fba.connection.close()