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/>.
21 from fba import commands
24 from fba.helpers import locking
26 logging.basicConfig(level=logging.WARNING)
27 logger = logging.getLogger(__name__)
33 logger.debug("init_parser(): CALLED!")
36 logger.debug("Initializing parser ...")
37 _PARSER = argparse.ArgumentParser(
38 description="Fetches block reasons from the fediverse",
39 epilog="Please note that some commands have optional arguments, you may want to try fba.py <command> --help to find them out.",
41 subparser_command = _PARSER.add_subparsers(
43 title="Commands to execute",
45 help="Command to perform",
48 ### Check instance ###
49 parser = subparser_command.add_parser(
51 help="Checks given instance if it exists and returns proper exit code"
53 parser.add_argument("--domain", required=True, help="Instance name (aka. domain) to check")
54 parser.set_defaults(command=commands.check_instance)
56 ### Fetch from bka.li ###
57 parser = subparser_command.add_parser(
59 help="Fetches domain names from bka.li API",
61 parser.set_defaults(command=commands.fetch_bkali)
63 ### Fetch blocks from registered instances or given ###
64 parser = subparser_command.add_parser(
66 help="Fetches blocks from registered instances (run command fetch_instances first!).",
68 parser.add_argument("--domain", help="Instance name (aka. domain)")
69 parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
70 parser.set_defaults(command=commands.fetch_blocks)
72 ### Fetch blocks from chaos.social ###
73 parser = subparser_command.add_parser(
75 help="Fetches blocks from chaos.social's meta sub domain.",
77 parser.set_defaults(command=commands.fetch_cs)
79 ### Fetch blocks from a FBA-specific RSS feed ###
80 parser = subparser_command.add_parser(
82 help="Fetches domains from a FBA-specific RSS feed.",
84 parser.add_argument("--feed", required=True, help="RSS feed to fetch domains from (e.g. https://fba.ryoma.agency/rss?domain=foo.bar).")
85 parser.set_defaults(command=commands.fetch_fba_rss)
87 ### Fetch blocks from FBA's bot account ###
88 parser = subparser_command.add_parser(
90 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.",
92 parser.set_defaults(command=commands.fetch_fbabot_atom)
94 ### Fetch blocks from oliphant's GIT repository ###
95 parser = subparser_command.add_parser(
97 help="Fetches CSV files (block recommendations) for more possible instances to disover",
99 parser.add_argument("--domain", help="Instance name (aka. domain) to check")
100 parser.set_defaults(command=commands.fetch_oliphant)
102 ### Fetch instances from given initial instance ###
103 parser = subparser_command.add_parser(
105 help="Fetches instances (aka. \"domains\") from an initial instance.",
107 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 .")
108 parser.add_argument("--single", action="store_true", help="Only fetch given instance.")
109 parser.set_defaults(command=commands.fetch_instances)
111 ### Fetch blocks from static text file(s) ###
112 parser = subparser_command.add_parser(
114 help="Fetches text/plain files as simple domain lists",
116 parser.set_defaults(command=commands.fetch_txt)
118 ### Fetch blocks from fediverse.observer ###
119 parser = subparser_command.add_parser(
121 help="Fetches blocks from fediverse.observer.",
123 parser.set_defaults(command=commands.fetch_observer)
125 ### Fetch instances from fedipact.online ###
126 parser = subparser_command.add_parser(
128 help="Fetches blocks from fedipact.online.",
130 parser.set_defaults(command=commands.fetch_fedipact)
132 logger.debug("init_parser(): EXIT!")
135 logger.debug("run_command(): CALLED!")
136 args = _PARSER.parse_args()
137 logger.debug(f"args[{type(args)}]={args}")
138 status = args.command(args)
139 logger.debug("status={status} - EXIT!")
140 return status if isinstance(status, int) else 0
143 logger.debug("Closing database connection ...")
144 fba.connection.close()
146 logger.debug("Shutdown completed.")