]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Fri, 2 Jun 2023 21:01:20 +0000 (23:01 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 2 Jun 2023 21:01:20 +0000 (23:01 +0200)
- added Python script to fetch domains from bka.la (thank you to Kromonos)

fetch_bkali.py [new file with mode: 0755]

diff --git a/fetch_bkali.py b/fetch_bkali.py
new file mode 100755 (executable)
index 0000000..f09612d
--- /dev/null
@@ -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 <https://www.gnu.org/licenses/>.
+
+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()