From 9cb874e872dc415cb31736da77894d293bf60912 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 5 Jun 2023 23:41:07 +0200 Subject: [PATCH] Continued: - add argument --single to commands.fetch_instances() which only fetches given instance - int() doesn't "magically" turn NoneType to 0, PHP would do it, so let's handle this here by ourself --- fba/boot.py | 5 +++-- fba/commands.py | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/fba/boot.py b/fba/boot.py index 1a89741..01fda7b 100644 --- a/fba/boot.py +++ b/fba/boot.py @@ -105,6 +105,7 @@ def init_parser(): help="Fetches instances (aka. \"domains\") from an initial instance.", ) 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 .") + parser.add_argument("--single", action="store_true", help="Only fetch given instance.") parser.set_defaults(command=commands.fetch_instances) # DEBUG: print("DEBUG: init_parser(): EXIT!") @@ -113,9 +114,9 @@ def run_command(): # DEBUG: print("DEBUG: run_command(): CALLED!") args = _PARSER.parse_args() print(f"DEBUG: args[{type(args)}]={args}") - status = int(args.command(args)) + status = args.command(args) # DEBUG: print("DEBUG: status={status} - EXIT!") - return status + return status if type(status) == int else 0 def shutdown(): print("DEBUG: Closing database connection ...") diff --git a/fba/commands.py b/fba/commands.py index 3bad9dd..e22646a 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -768,6 +768,10 @@ def fetch_instances(args: argparse.Namespace): # Initial fetch fba.fetch_instances(args.domain, None, None, sys.argv[0]) + if args.single: + print(f"DEBUG: Not fetching more instances - EXIT!") + return + # Loop through some instances fba.cursor.execute( "SELECT domain, origin, software, nodeinfo_url FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial', 'bookwyrm', 'takahe', 'lemmy') AND (last_instance_fetch IS NULL OR last_instance_fetch < ?) ORDER BY rowid DESC", [time.time() - config.get("recheck_instance")] -- 2.39.5