63 lines
2.0 KiB
Python
63 lines
2.0 KiB
Python
import json
|
|
from pathlib import Path
|
|
|
|
SUPPORT_MAPPINGS = {
|
|
'supportsSora': 'supportsHiyoku',
|
|
}
|
|
|
|
def add_supports(file_path, mappings):
|
|
"""Add support keys to JSON files based on trigger keys"""
|
|
try:
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|
data = json.load(f)
|
|
|
|
if not isinstance(data, dict):
|
|
return False, "Not a dict"
|
|
|
|
modified = False
|
|
|
|
if any(key in data for key in mappings.keys()):
|
|
for trigger_key, new_key in mappings.items():
|
|
if data.get(trigger_key) == True and new_key not in data:
|
|
data[new_key] = True
|
|
modified = True
|
|
|
|
else:
|
|
for key, value in data.items():
|
|
if isinstance(value, dict):
|
|
for trigger_key, new_key in mappings.items():
|
|
if value.get(trigger_key) == True and new_key not in value:
|
|
value[new_key] = True
|
|
modified = True
|
|
|
|
if modified:
|
|
with open(file_path, 'w', encoding='utf-8') as f:
|
|
json.dump(data, f, indent=2, ensure_ascii=False)
|
|
return True, "Modified"
|
|
else:
|
|
return False, "No changes"
|
|
except Exception as e:
|
|
return False, f"Error: {str(e)}"
|
|
|
|
if __name__ == "__main__":
|
|
script_dir = Path(__file__).parent
|
|
|
|
print("Processing JSON files...")
|
|
print("=" * 60)
|
|
|
|
index_file = script_dir / "index.json"
|
|
if index_file.exists():
|
|
success, msg = add_supports(index_file, SUPPORT_MAPPINGS)
|
|
print(f"index.json: {msg}")
|
|
|
|
for json_file in script_dir.rglob("*.json"):
|
|
if json_file.name == "index.json" and json_file.parent == script_dir:
|
|
continue
|
|
|
|
success, msg = add_supports(json_file, SUPPORT_MAPPINGS)
|
|
if success:
|
|
print(f"✓ {json_file.relative_to(script_dir)}: {msg}")
|
|
|
|
print("=" * 60)
|
|
print("Done!")
|