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
22 from fba import database
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 todon.eu wiki ###
80 parser = subparser_command.add_parser(
82 help="Fetches blocks from todon.eu's wiki.",
84 parser.set_defaults(command=commands.fetch_todon_wiki)
86 ### Fetch blocks from a FBA-specific RSS feed ###
87 parser = subparser_command.add_parser(
89 help="Fetches domains from a FBA-specific RSS feed.",
91 parser.add_argument("--feed", required=True, help="RSS feed to fetch domains from (e.g. https://fba.ryoma.agency/rss?domain=foo.bar).")
92 parser.set_defaults(command=commands.fetch_fba_rss)
94 ### Fetch blocks from FBA's bot account ###
95 parser = subparser_command.add_parser(
97 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.",
99 parser.set_defaults(command=commands.fetch_fbabot_atom)
101 ### Fetch blocks from oliphant's GIT repository ###
102 parser = subparser_command.add_parser(
104 help="Fetches CSV files (block recommendations) for more possible instances to disover",
106 parser.add_argument("--domain", help="Instance name (aka. domain) to check")
107 parser.set_defaults(command=commands.fetch_oliphant)
109 ### Fetch instances from given initial instance ###
110 parser = subparser_command.add_parser(
112 help="Fetches instances (aka. \"domains\") from an initial instance.",
114 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 .")
115 parser.add_argument("--single", action="store_true", help="Only fetch given instance.")
116 parser.set_defaults(command=commands.fetch_instances)
118 ### Fetch blocks from static text file(s) ###
119 parser = subparser_command.add_parser(
121 help="Fetches text/plain files as simple domain lists",
123 parser.set_defaults(command=commands.fetch_txt)
125 ### Fetch blocks from fediverse.observer ###
126 parser = subparser_command.add_parser(
128 help="Fetches blocks from fediverse.observer.",
130 parser.set_defaults(command=commands.fetch_observer)
132 ### Fetch instances from fedipact.online ###
133 parser = subparser_command.add_parser(
135 help="Fetches blocks from fedipact.online.",
137 parser.set_defaults(command=commands.fetch_fedipact)
139 logger.debug("init_parser(): EXIT!")
142 logger.debug("run_command(): CALLED!")
143 args = _PARSER.parse_args()
144 logger.debug(f"args[{type(args)}]={args}")
145 status = args.command(args)
146 logger.debug("status={status} - EXIT!")
147 return status if isinstance(status, int) else 0
150 logger.debug("Closing database connection ...")
151 database.connection.close()
153 logger.debug("Shutdown completed.")