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/>.
22 from fba import commands
26 lockfile = tempfile.gettempdir() + '/fba.lock'
33 print(f"DEBUG: Acquiring lock: '{lockfile}'")
34 LOCK = zc.lockfile.LockFile(lockfile)
35 print("DEBUG: Lock obtained.")
37 except zc.lockfile.LockError:
38 print(f"ERROR: Cannot aquire lock: '{lockfile}'")
42 # DEBUG: print("DEBUG: init_parser(): CALLED!")
45 print("DEBUG: Initializing parser ...")
46 _PARSER = argparse.ArgumentParser(
47 description="Fetches block reasons from the fediverse",
48 epilog="Please note that some commands have optional arguments, you may want to try fba.py <command> --help to find them out.",
50 subparser_command = _PARSER.add_subparsers(
52 title="Commands to execute",
54 help="Command to perform",
57 ### Check instance ###
58 parser = subparser_command.add_parser(
60 help="Checks given instance if it exists and returns proper exit code"
62 parser.add_argument("--domain", required=True, help="Instance name (aka. domain) to check")
63 parser.set_defaults(command=commands.check_instance)
65 ### Fetch from bka.li ###
66 parser = subparser_command.add_parser(
68 help="Fetches domain names from bka.li API",
70 parser.set_defaults(command=commands.fetch_bkali)
72 ### Fetch blocks from registered instances or given ###
73 parser = subparser_command.add_parser(
75 help="Fetches blocks from registered instances (run command fetch_instances first!).",
77 parser.add_argument("--domain", help="Instance name (aka. domain) to fetch blocks from")
78 parser.set_defaults(command=commands.fetch_blocks)
80 ### Fetch blocks from chaos.social ###
81 parser = subparser_command.add_parser(
83 help="Fetches blocks from chaos.social's meta sub domain.",
85 parser.set_defaults(command=commands.fetch_cs)
87 ### Fetch blocks from a FBA-specific RSS feed ###
88 parser = subparser_command.add_parser(
90 help="Fetches domains from a FBA-specific RSS feed.",
92 parser.add_argument("--feed", required=True, help="RSS feed to fetch domains from (e.g. https://fba.ryoma.agency/rss?domain=foo.bar).")
93 parser.set_defaults(command=commands.fetch_fba_rss)
95 ### Fetch blocks from FBA's bot account ###
96 parser = subparser_command.add_parser(
98 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.",
100 parser.set_defaults(command=commands.fetch_fbabot_atom)
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.set_defaults(command=commands.fetch_instances)
110 # DEBUG: print("DEBUG: init_parser(): EXIT!")
113 # DEBUG: print("DEBUG: run_command(): CALLED!")
114 args = _PARSER.parse_args()
115 print(f"DEBUG: args[{type(args)}]={args}")
117 # DEBUG: print("DEBUG: run_command(): EXIT!")
120 print("DEBUG: Closing database connection ...")
121 fba.connection.close()
124 print("DEBUG: Releasing lock ...")
126 print(f"DEBUG: Deleting lockfile='{lockfile}' ...")
129 print("DEBUG: Shutdown completed.")