Update generate-touch-layouts-ids.py

This commit is contained in:
redphx 2024-05-07 21:00:53 +07:00
parent b1e7e71f86
commit 6f81137cd4

View File

@ -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)