forked from vegastrike/Assets-Production
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.py
29 lines (23 loc) · 810 Bytes
/
convert.py
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
# Convert weapon_list.xml to weapons.json
import json
import xml.etree.ElementTree as et
weapon_xml = et.parse('weapon_list.xml')
root = weapon_xml.getroot()
string_keys = ["type","name","mountsize","file","soundwav"]
weapons = []
for elem in root:
weapon_dict = {}
weapon_dict['type'] = elem.tag
weapon_dict.update(elem.attrib)
for child in elem:
prefix = child.tag
for key,value in child.attrib.items():
if key in string_keys:
weapon_dict[prefix + '.' + key] = value
else:
weapon_dict[prefix + '.' + key] = float(value)
weapons.append(weapon_dict)
json_object = json.dumps(weapons, indent = 4)
with open("weapons.json", "w") as json_file:
json_file.write(json_object)
print(json_object)