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
22 from fba.helpers import locking
27 # DEBUG: print("DEBUG: init_parser(): CALLED!")
30 # DEBUG: print("DEBUG: Initializing parser ...")
31 _PARSER = argparse.ArgumentParser(
32 description="Fetches block reasons from the fediverse",
33 epilog="Please note that some commands have optional arguments, you may want to try fba.py <command> --help to find them out.",
35 subparser_command = _PARSER.add_subparsers(
37 title="Commands to execute",
39 help="Command to perform",
42 ### Check instance ###
43 parser = subparser_command.add_parser(
45 help="Checks given instance if it exists and returns proper exit code"
47 parser.add_argument("--domain", required=True, help="Instance name (aka. domain) to check")
48 parser.set_defaults(command=commands.check_instance)
50 ### Fetch from bka.li ###
51 parser = subparser_command.add_parser(
53 help="Fetches domain names from bka.li API",
55 parser.set_defaults(command=commands.fetch_bkali)
57 ### Fetch blocks from registered instances or given ###
58 parser = subparser_command.add_parser(
60 help="Fetches blocks from registered instances (run command fetch_instances first!).",
62 parser.add_argument("--domain", help="Instance name (aka. domain)")
63 parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
64 parser.set_defaults(command=commands.fetch_blocks)
66 ### Fetch blocks from chaos.social ###
67 parser = subparser_command.add_parser(
69 help="Fetches blocks from chaos.social's meta sub domain.",
71 parser.set_defaults(command=commands.fetch_cs)
73 ### Fetch blocks from a FBA-specific RSS feed ###
74 parser = subparser_command.add_parser(
76 help="Fetches domains from a FBA-specific RSS feed.",
78 parser.add_argument("--feed", required=True, help="RSS feed to fetch domains from (e.g. https://fba.ryoma.agency/rss?domain=foo.bar).")
79 parser.set_defaults(command=commands.fetch_fba_rss)
81 ### Fetch blocks from FBA's bot account ###
82 parser = subparser_command.add_parser(
84 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.",
86 parser.set_defaults(command=commands.fetch_fbabot_atom)
88 ### Fetch blocks from oliphant's GIT repository ###
89 parser = subparser_command.add_parser(
91 help="Fetches CSV files (block recommendations) for more possible instances to disover",
93 parser.add_argument("--domain", help="Instance name (aka. domain) to check")
94 parser.set_defaults(command=commands.fetch_oliphant)
96 ### Fetch instances from given initial instance ###
97 parser = subparser_command.add_parser(
99 help="Fetches instances (aka. \"domains\") from an initial instance.",
101 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 .")
102 parser.add_argument("--single", action="store_true", help="Only fetch given instance.")
103 parser.set_defaults(command=commands.fetch_instances)
105 ### Fetch blocks from static text file(s) ###
106 parser = subparser_command.add_parser(
108 help="Fetches text/plain files as simple domain lists",
110 parser.set_defaults(command=commands.fetch_txt)
112 ### Fetch blocks from fediverse.observer ###
113 parser = subparser_command.add_parser(
115 help="Fetches blocks from fediverse.observer.",
117 parser.set_defaults(command=commands.fetch_observer)
119 # DEBUG: print("DEBUG: init_parser(): EXIT!")
122 # DEBUG: print("DEBUG: run_command(): CALLED!")
123 args = _PARSER.parse_args()
124 # DEBUG: print(f"DEBUG: args[{type(args)}]={args}")
125 status = args.command(args)
126 # DEBUG: print("DEBUG: status={status} - EXIT!")
127 return status if isinstance(status, int) else 0
130 # DEBUG: print("DEBUG: Closing database connection ...")
131 fba.connection.close()
133 # DEBUG: print("DEBUG: Shutdown completed.")