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/>.
29 fetched = fba.post_json_api("gql.api.bka.li", "/v1/graphql", json.dumps({
30 "query": "query domainlist {nodeinfo(order_by: {domain: asc}) {domain}}"
33 # DEBUG: print(f"DEBUG: fetched({len(fetched)})[]='{type(fetched)}'")
35 raise Exception("WARNING: Returned no records")
36 elif not "data" in fetched:
37 raise Exception(f"WARNING: fetched()={len(fetched)} does not contain element 'data'")
38 elif not "nodeinfo" in fetched["data"]:
39 raise Exception(f"WARNING: fetched()={len(fetched['data'])} does not contain element 'nodeinfo'")
41 for entry in fetched["data"]["nodeinfo"]:
42 # DEBUG: print(f"DEBUG: entry['{type(entry)}']='{entry}'")
43 if not "domain" in entry:
44 print(f"WARNING: entry does not contain 'domain' - SKIPPED!")
46 elif not validators.domain(entry["domain"]):
47 print(f"WARNING: domain='{entry['domain']}' is not a valid domain - SKIPPED!")
49 elif fba.is_blacklisted(entry["domain"]):
50 # DEBUG: print(f"DEBUG: domain='{entry['domain']}' is blacklisted - SKIPPED!")
52 elif fba.is_instance_registered(entry["domain"]):
53 # DEBUG: print(f"DEBUG: domain='{entry['domain']}' is already registered - SKIPPED!")
56 # DEBUG: print(f"DEBUG: Adding domain='{entry['domain']}' ...")
57 domains.append(entry["domain"])
59 except BaseException as e:
60 print(f"ERROR: Cannot fetch graphql,exception[{type(e)}]:'{str(e)}'")
64 # DEBUG: print(f"DEBUG: domains()={len(domains)}")
66 print(f"INFO: Adding {len(domains)} new instances ...")
67 for domain in domains:
68 print(f"INFO: Fetching instances from domain='{domain}' ...")
69 fba.fetch_instances(domain, None, None, sys.argv[0])