]> git.mxchange.org Git - fba.git/blob - fetch_bkali.py
Continued:
[fba.git] / fetch_bkali.py
1 #!/usr/bin/python3
2 # -*- coding: utf-8 -*-
3
4 # Fedi API Block - An aggregator for fetching blocking data from fediverse nodes
5 # Copyright (C) 2023 Free Software Foundation
6 #
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.
11 #
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.
16 #
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/>.
19
20 import json
21 import sys
22 import validators
23 import fba
24
25 domains = list()
26 try:
27     fetched = fba.post_json_api("gql.api.bka.li", "/v1/graphql", json.dumps({
28         "query": "query domainlist {nodeinfo(order_by: {domain: asc}) {domain}}"
29     }))
30
31     # DEBUG: print(f"DEBUG: fetched({len(fetched)})[]='{type(fetched)}'")
32     if len(fetched) > 0 and "data" in fetched and "nodeinfo" in fetched["data"]:
33         for entry in fetched["data"]["nodeinfo"]:
34             # DEBUG: print(f"DEBUG: entry['{type(entry)}']='{entry}'")
35             if not "domain" in entry:
36                 print(f"WARNING: entry does not contain 'domain' - SKIPPED!")
37                 continue
38             elif not validators.domain(entry["domain"]):
39                 print(f"WARNING: domain='{entry['domain']}' is {entry['domain']}' is not a valid domain - SKIPPED!")
40                 continue
41             elif fba.is_blacklisted(entry["domain"]):
42                 # DEBUG: print(f"DEBUG: domain='blacklisted - SKIPPED!")
43                 continue
44
45             domains.append(entry["domain"])
46
47 except BaseException as e:
48     print(f"ERROR: Cannot fetch graphql,exception[{type(e)}]:'{str(e)}'")
49     sys.exit(255)
50
51 # Show domains
52 # DEBUG: print(f"DEBUG: domains()={len(domains)}")
53 if len(domains) > 0:
54     print(f"INFO: Adding {len(domains)} new instances ...")
55     for domain in domains:
56         print(f"INFO: Fetching instances from domain='{domain}' ...")
57         fba.fetch_instances(domain, None, None, sys.argv[0])
58
59 fba.connection.close()