forked from eirikmun/xwing-data2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntaxfix.py
More file actions
40 lines (33 loc) · 1.69 KB
/
syntaxfix.py
File metadata and controls
40 lines (33 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import json
base_path = r"C:\Users\gregk\Documents\GitHub\xwa-points\xwing-data2\data\pilots"
for root, _, files in os.walk(base_path):
for file in files:
if file.endswith(".json"):
file_path = os.path.join(root, file)
with open(file_path, "r", encoding="utf-8") as f:
try:
data = json.load(f)
except json.JSONDecodeError as e:
print(f"❌ JSON error in {file_path}: {e}")
continue
changed = False
if "pilots" in data:
for pilot in data["pilots"]:
# Replace in 'ability'
if "ability" in pilot and isinstance(pilot["ability"], str):
updated = pilot["ability"].replace("[Missiles]", "[Missile]")
if updated != pilot["ability"]:
pilot["ability"] = updated
changed = True
# Replace in 'shipAbility.text'
if "shipAbility" in pilot and isinstance(pilot["shipAbility"], dict):
if "text" in pilot["shipAbility"] and isinstance(pilot["shipAbility"]["text"], str):
updated = pilot["shipAbility"]["text"].replace("[Missiles]", "[Missile]")
if updated != pilot["shipAbility"]["text"]:
pilot["shipAbility"]["text"] = updated
changed = True
if changed:
with open(file_path, "w", encoding="utf-8") as f:
json.dump(data, f, indent=2)
print(f"✅ Updated: {file_path}")