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.INFO)
27 logger = logging.getLogger(__name__)
33 logger.debug("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.",
43 _PARSER.add_argument("--debug", action="store_const", dest="log_level", const=logging.DEBUG, help="Full debug output")
46 subparser_command = _PARSER.add_subparsers(
48 title="Commands to execute",
50 help="Command to perform",
53 ### Check instance ###
54 parser = subparser_command.add_parser(
56 help="Checks given instance if it exists and returns proper exit code"
58 parser.add_argument("--domain", required=True, help="Instance name (aka. domain) to check")
59 parser.set_defaults(command=commands.check_instance)
61 ### Fetch from bka.li ###
62 parser = subparser_command.add_parser(
64 help="Fetches domain names from bka.li API",
66 parser.set_defaults(command=commands.fetch_bkali)
68 ### Fetch blocks from registered instances or given ###
69 parser = subparser_command.add_parser(
71 help="Fetches blocks from registered instances (run command fetch_instances first!).",
73 parser.add_argument("--domain", help="Instance name (aka. domain)")
74 parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
75 parser.set_defaults(command=commands.fetch_blocks)
77 ### Fetch blocks from chaos.social ###
78 parser = subparser_command.add_parser(
80 help="Fetches blocks from chaos.social's meta sub domain.",
82 parser.set_defaults(command=commands.fetch_cs)
84 ### Fetch blocks from todon.eu wiki ###
85 parser = subparser_command.add_parser(
87 help="Fetches blocks from todon.eu's wiki.",
89 parser.set_defaults(command=commands.fetch_todon_wiki)
91 ### Fetch blocks from a FBA-specific RSS feed ###
92 parser = subparser_command.add_parser(
94 help="Fetches domains from a FBA-specific RSS feed.",
96 parser.add_argument("--feed", required=True, help="RSS feed to fetch domains from (e.g. https://fba.ryoma.agency/rss?domain=foo.bar).")
97 parser.set_defaults(command=commands.fetch_fba_rss)
99 ### Fetch blocks from FBA's bot account ###
100 parser = subparser_command.add_parser(
102 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.",
104 parser.set_defaults(command=commands.fetch_fbabot_atom)
106 ### Fetch blocks from oliphant's GIT repository ###
107 parser = subparser_command.add_parser(
109 help="Fetches CSV files (block recommendations) for more possible instances to disover",
111 parser.add_argument("--domain", help="Instance name (aka. domain) to check")
112 parser.set_defaults(command=commands.fetch_oliphant)
114 ### Fetch instances from given initial instance ###
115 parser = subparser_command.add_parser(
117 help="Fetches instances (aka. \"domains\") from an initial instance.",
119 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 .")
120 parser.add_argument("--single", action="store_true", help="Only fetch given instance.")
121 parser.set_defaults(command=commands.fetch_instances)
123 ### Fetch blocks from static text file(s) ###
124 parser = subparser_command.add_parser(
126 help="Fetches text/plain files as simple domain lists",
128 parser.set_defaults(command=commands.fetch_txt)
130 ### Fetch blocks from joinfediverse.wiki ###
131 parser = subparser_command.add_parser(
132 "fetch_joinfediverse",
133 help="Fetches FediBlock page from joinfediverse.wiki",
135 parser.set_defaults(command=commands.fetch_joinfediverse)
137 ### Fetch blocks from fediverse.observer ###
138 parser = subparser_command.add_parser(
140 help="Fetches blocks from fediverse.observer.",
142 parser.set_defaults(command=commands.fetch_observer)
143 parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
145 ### Fetch instances from fedipact.online ###
146 parser = subparser_command.add_parser(
148 help="Fetches blocks from fedipact.online.",
150 parser.set_defaults(command=commands.fetch_fedipact)
152 ### Fetch from pixelfed.org's API ###
153 parser = subparser_command.add_parser(
154 "fetch_pixelfed_api",
155 help="Fetches domain names from pixelfed.org's API",
157 parser.set_defaults(command=commands.fetch_pixelfed_api)
159 logger.debug("EXIT!")
162 logger.debug("CALLED!")
163 args = _PARSER.parse_args()
165 if args.log_level is not None:
166 loggers = [logging.getLogger(name) for name in logging.root.manager.loggerDict]
167 for _logger in loggers:
168 _logger.setLevel(args.log_level)
170 logger.debug("args[%s]='%s'", type(args), args)
171 status = args.command(args)
173 logger.debug("status=%d - EXIT!", status)
177 logger.debug("Closing database connection ...")
178 database.connection.close()
180 logger.debug("Shutdown completed.")