From 0b6c9e21a136b3b4aefb01314316ed2c0c0f1909 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Tue, 12 Sep 2023 09:00:29 +0200 Subject: [PATCH] refacto tinfoil --- commands/tinfoil.py | 61 +++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/commands/tinfoil.py b/commands/tinfoil.py index e32aa3b..ebd792d 100755 --- a/commands/tinfoil.py +++ b/commands/tinfoil.py @@ -9,41 +9,19 @@ import requests parser = argparse.ArgumentParser() parser.add_argument("-r", "--remote", type=str, required=True) +parser.add_argument("-f", "--force", action=argparse.BooleanOptionalAction) args = parser.parse_args() remote = args.remote +force = args.force -req_titles = requests.get( - "https://raw.githubusercontent.com/blawar/titledb/master/FR.fr.json" -) -json_titles = req_titles.json() -titles = [] -for json_title in json_titles: - titles.append(json_titles[json_title]["id"]) -print("Titles OK") -proc_bases = subprocess.run( - ["rclone", "lsf", f"{remote}:nsz/base"], - check=True, - capture_output=True, -) -bases = proc_bases.stdout.decode().split("\n") -print("Base OK") - -proc_dlcs = subprocess.run( - ["rclone", "lsf", f"{remote}:nsz/dlc"], - check=True, - capture_output=True, -) -dlcs = proc_dlcs.stdout.decode().split("\n") -print("DLC OK") - -proc_updates = subprocess.run( - ["rclone", "lsf", f"{remote}:nsz/updates"], - check=True, - capture_output=True, -) -updates = proc_updates.stdout.decode().split("\n") -print("Updates OK") +def drive_list(path): + proc = subprocess.run( + ["rclone", "lsf", f"{remote}:{path}"], + check=True, + capture_output=True, + ) + return proc.stdout.decode().split("\n") def download(path, file): @@ -57,6 +35,25 @@ def download(path, file): ) +req_titles = requests.get( + "https://raw.githubusercontent.com/blawar/titledb/master/FR.fr.json" +) +json_titles = req_titles.json() +titles = [] +for json_title in json_titles: + titles.append(json_titles[json_title]["id"]) +print("Titles OK") + +bases = drive_list("nsz/base") +print("Base OK") + +dlcs = drive_list("nsz/dlc") +print("DLC OK") + +updates = drive_list("nsz/updates") +print("Updates OK") + + for base in bases: re_id = re.search(r"\[([0-9A-F]*)\]", base) @@ -65,7 +62,7 @@ for base in bases: id = re_id.group(1) - if id not in titles: + if not force and id not in titles: continue id = id[0:-4]