2 # -*- coding: utf-8 -*-
4 # Fedi API Block - An aggregator for fetching blocking data from fediverse nodes
5 # Copyright (C) 2023 Free Software Foundation
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published
9 # by the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <https://www.gnu.org/licenses/>.
27 fetched = fba.post_json_api("gql.api.bka.li", "/v1/graphql", json.dumps({
28 "query": "query domainlist {nodeinfo(order_by: {domain: asc}) {domain}}"
31 # DEBUG: print(f"DEBUG: fetched({len(fetched)})[]='{type(fetched)}'")
33 raise Exception("WARNING: Returned no records")
34 elif not "data" in fetched:
35 raise Exception(f"WARNING: fetched()={len(fetched)} does not contain element 'data'")
36 elif not "nodeinfo" in fetched["data"]:
37 raise Exception(f"WARNING: fetched()={len(fetched['data'])} does not contain element 'nodeinfo'")
39 for entry in fetched["data"]["nodeinfo"]:
40 # DEBUG: print(f"DEBUG: entry['{type(entry)}']='{entry}'")
41 if not "domain" in entry:
42 print(f"WARNING: entry does not contain 'domain' - SKIPPED!")
44 elif not validators.domain(entry["domain"]):
45 print(f"WARNING: domain='{entry['domain']}' is not a valid domain - SKIPPED!")
47 elif fba.is_blacklisted(entry["domain"]):
48 # DEBUG: print(f"DEBUG: domain='{entry['domain']}' is blacklisted - SKIPPED!")
50 elif fba.is_instance_registered(entry["domain"]):
51 # DEBUG: print(f"DEBUG: domain='{entry['domain']}' is already registered - SKIPPED!")
54 # DEBUG: print(f"DEBUG: Adding domain='{entry['domain']}' ...")
55 domains.append(entry["domain"])
57 except BaseException as e:
58 print(f"ERROR: Cannot fetch graphql,exception[{type(e)}]:'{str(e)}'")
61 # DEBUG: print(f"DEBUG: domains()={len(domains)}")
65 print(f"INFO: Adding {len(domains)} new instances ...")
66 for domain in domains:
67 print(f"INFO: Fetching instances from domain='{domain}' ...")
68 fba.fetch_instances(domain, None, None, sys.argv[0])