From 6f81137cd4f0bcd6b4d817b0fcf5e20ca43a52d6 Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Tue, 7 May 2024 21:00:53 +0700 Subject: [PATCH] Update generate-touch-layouts-ids.py --- scripts/generate-touch-layouts-ids.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/scripts/generate-touch-layouts-ids.py b/scripts/generate-touch-layouts-ids.py index 983f0fb..6096118 100644 --- a/scripts/generate-touch-layouts-ids.py +++ b/scripts/generate-touch-layouts-ids.py @@ -1,28 +1,25 @@ +import json import os FOLDER = 'touch-layouts' OUTPUT_FILE = os.path.join(FOLDER, 'ids.json') -gameIds = list() +product_ids = list() # Get files in folder for file in os.listdir(FOLDER): if not file.endswith('.json') or file == 'ids.json': continue - # Get game ID from file name (as int so we can sort the list later) - gameId = int(file.replace('.json', '')) - gameIds.append(gameId) + with open(os.path.join(FOLDER, file)) as fp: + content = json.load(fp) + product_ids.append(content['product_id']) -# Sort list of ints -gameIds.sort() -# Convert int to string -gameIds = list(map((lambda x: str(x)), gameIds)) - -# Generate output string -output = '[\n ' + ',\n '.join(gameIds) + '\n]\n' +# Sort list +product_ids.sort() # Write to file +output = json.dumps(product_ids, separators=(',', ': '), indent=2) + '\n' with open(OUTPUT_FILE, 'w') as fp: fp.write(output)