From: Roland Häder Date: Mon, 5 Jun 2023 21:41:07 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9cb874e872dc415cb31736da77894d293bf60912;p=fba.git 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 --- 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")]