104 lines
3.2 KiB
Python
104 lines
3.2 KiB
Python
import os
|
|
import json
|
|
|
|
def generate_root_json(directory):
|
|
data = {
|
|
"metadata": {
|
|
"page": "main",
|
|
"author": "Benjamyn Love + JMH"
|
|
},
|
|
"roms": {},
|
|
"utilities": []
|
|
}
|
|
excluded_dirs = ["emulation", "@recycle", "poobs"] # Add your excluded directory names here
|
|
for dir_name in os.listdir(directory):
|
|
dir_path = os.path.join(directory, dir_name)
|
|
uri = "/" + dir_name.lower().replace(" ", "-")
|
|
if os.path.isdir(dir_path):
|
|
if dir_name in excluded_dirs:
|
|
utilities_entry = {
|
|
"name": dir_name,
|
|
"uri": uri
|
|
}
|
|
data["utilities"].append(utilities_entry)
|
|
else:
|
|
console_name = dir_name
|
|
subdirectories = 0
|
|
files = 0
|
|
for entry in os.scandir(dir_path):
|
|
if entry.is_dir():
|
|
subdirectories += 1
|
|
elif entry.is_file():
|
|
files += 1
|
|
|
|
uri = "/" + console_name.lower().replace(" ", "-")
|
|
|
|
console = {
|
|
"name": console_name,
|
|
"uri": uri,
|
|
"subdirectories": subdirectories,
|
|
"files": files
|
|
}
|
|
data["roms"][console_name.lower()] = console
|
|
# Save the JSON data to a file
|
|
with open('game_consoles2.json', 'w') as json_file:
|
|
json.dump(data, json_file, indent=4)
|
|
|
|
directory = '/Users/jordanmartin/stuff/rm_site_dir_test/10.6.9.5/'
|
|
json_data = generate_root_json(directory)
|
|
|
|
def generate_roms_json(directories):
|
|
'''NEEDS WORK!'''
|
|
data = {
|
|
"roms": []
|
|
}
|
|
|
|
for directory in directories:
|
|
dir_name = directory["name"]
|
|
dir_path = directory["path"]
|
|
console_entry = {
|
|
"name": dir_name,
|
|
"uri": "/" + dir_name.lower().replace(" ", "-"),
|
|
"contents": {
|
|
"base": {},
|
|
"updates": [],
|
|
"dlc": []
|
|
}
|
|
}
|
|
base_rom = None
|
|
updates = []
|
|
dlc = []
|
|
|
|
for entry in os.scandir(dir_path):
|
|
if entry.is_file():
|
|
file_name = entry.name
|
|
file_path = entry.path
|
|
file_size = os.path.getsize(file_path)
|
|
|
|
if file_name.lower().endswith(".nsp"):
|
|
if "[v0]" in file_name:
|
|
base_rom = {
|
|
"name": file_name,
|
|
"size": file_size
|
|
}
|
|
elif "[v" in file_name:
|
|
updates.append({
|
|
"name": file_name,
|
|
"size": file_size
|
|
})
|
|
else:
|
|
dlc.append({
|
|
"name": file_name,
|
|
"size": file_size
|
|
})
|
|
|
|
console_entry["contents"]["base"] = base_rom
|
|
console_entry["contents"]["updates"] = updates
|
|
console_entry["contents"]["dlc"] = dlc
|
|
|
|
data["roms"].append(console_entry)
|
|
|
|
return data
|
|
|
|
|