1 # Fedi API Block - An aggregator for fetching blocking data from fediverse nodes
2 # Copyright (C) 2023 Free Software Foundation
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published
6 # by the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 from fba import commands
21 from fba import locking
26 # DEBUG: print("DEBUG: init_parser(): CALLED!")
29 # DEBUG: print("DEBUG: Initializing parser ...")
30 _PARSER = argparse.ArgumentParser(
31 description="Fetches block reasons from the fediverse",
32 epilog="Please note that some commands have optional arguments, you may want to try fba.py <command> --help to find them out.",
34 subparser_command = _PARSER.add_subparsers(
36 title="Commands to execute",
38 help="Command to perform",
41 ### Check instance ###
42 parser = subparser_command.add_parser(
44 help="Checks given instance if it exists and returns proper exit code"
46 parser.add_argument("--domain", required=True, help="Instance name (aka. domain) to check")
47 parser.set_defaults(command=commands.check_instance)
49 ### Fetch from bka.li ###
50 parser = subparser_command.add_parser(
52 help="Fetches domain names from bka.li API",
54 parser.set_defaults(command=commands.fetch_bkali)
56 ### Fetch blocks from registered instances or given ###
57 parser = subparser_command.add_parser(
59 help="Fetches blocks from registered instances (run command fetch_instances first!).",
61 parser.add_argument("--domain", help="Instance name (aka. domain) to fetch blocks from")
62 parser.set_defaults(command=commands.fetch_blocks)
64 ### Fetch blocks from chaos.social ###
65 parser = subparser_command.add_parser(
67 help="Fetches blocks from chaos.social's meta sub domain.",
69 parser.set_defaults(command=commands.fetch_cs)
71 ### Fetch blocks from a FBA-specific RSS feed ###
72 parser = subparser_command.add_parser(
74 help="Fetches domains from a FBA-specific RSS feed.",
76 parser.add_argument("--feed", required=True, help="RSS feed to fetch domains from (e.g. https://fba.ryoma.agency/rss?domain=foo.bar).")
77 parser.set_defaults(command=commands.fetch_fba_rss)
79 ### Fetch blocks from FBA's bot account ###
80 parser = subparser_command.add_parser(
82 help="Fetches ATOM feed with domains from FBA's bot account. You may wish to re-run this command several times (at least 3 with big instances) to have a decent amount of valid instances.",
84 parser.set_defaults(command=commands.fetch_fbabot_atom)
86 ### Fetch blocks from federater ###
87 parser = subparser_command.add_parser(
89 help="Fetches CSV file (block recommendations) for more possible instances to disover",
91 parser.set_defaults(command=commands.fetch_federater)
93 ### Fetch instances from given initial instance ###
94 parser = subparser_command.add_parser(
96 help="Fetches instances (aka. \"domains\") from an initial instance.",
98 parser.add_argument("--domain", required=True, help="Instance name (aka. domain) to fetch further instances from. Start with a large instance, e.g. mastodon.social .")
99 parser.add_argument("--single", action="store_true", help="Only fetch given instance.")
100 parser.set_defaults(command=commands.fetch_instances)
102 # DEBUG: print("DEBUG: init_parser(): EXIT!")
105 # DEBUG: print("DEBUG: run_command(): CALLED!")
106 args = _PARSER.parse_args()
107 # DEBUG: print(f"DEBUG: args[{type(args)}]={args}")
108 status = args.command(args)
109 # DEBUG: print("DEBUG: status={status} - EXIT!")
110 return status if isinstance(status, int) else 0
113 # DEBUG: print("DEBUG: Closing database connection ...")
114 fba.connection.close()
116 # DEBUG: print("DEBUG: Shutdown completed.")