This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
def add_anymex_support(file_path):
|
||||
"""Add supportsAnymex: true to JSON files that have supportsDartotsu: true"""
|
||||
try:
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
|
||||
# Check if this is a nested object (like in index.json)
|
||||
if isinstance(data, dict):
|
||||
modified = False
|
||||
|
||||
# Check if it's a single source entry
|
||||
if 'supportsDartotsu' in data:
|
||||
if data.get('supportsDartotsu') == True and 'supportsAnymex' not in data:
|
||||
data['supportsAnymex'] = True
|
||||
modified = True
|
||||
|
||||
# Check if it's index.json with multiple entries
|
||||
else:
|
||||
for key, value in data.items():
|
||||
if isinstance(value, dict) and 'supportsDartotsu' in value:
|
||||
if value.get('supportsDartotsu') == True and 'supportsAnymex' not in value:
|
||||
value['supportsAnymex'] = 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 needed"
|
||||
except Exception as e:
|
||||
return False, f"Error: {str(e)}"
|
||||
|
||||
# Get the script directory
|
||||
script_dir = Path(__file__).parent
|
||||
|
||||
# Process all JSON files
|
||||
print("Processing JSON files...")
|
||||
print("=" * 60)
|
||||
|
||||
# Process index.json
|
||||
index_file = script_dir / "index.json"
|
||||
if index_file.exists():
|
||||
success, msg = add_anymex_support(index_file)
|
||||
print(f"index.json: {msg}")
|
||||
|
||||
# Process all subdirectory JSON files
|
||||
for json_file in script_dir.rglob("*.json"):
|
||||
# Skip index.json as we already processed it
|
||||
if json_file.name == "index.json" and json_file.parent == script_dir:
|
||||
continue
|
||||
|
||||
success, msg = add_anymex_support(json_file)
|
||||
if success:
|
||||
print(f"✓ {json_file.relative_to(script_dir)}: {msg}")
|
||||
|
||||
print("=" * 60)
|
||||
print("Done!")
|
||||
Reference in New Issue
Block a user