-
Notifications
You must be signed in to change notification settings - Fork 47
/
update_modifiers.py
43 lines (36 loc) · 1.5 KB
/
update_modifiers.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import glob
import json
modifiers = []
for modifier_category_idx, modifier_category_path in enumerate(
glob.glob('modifiers/*')):
modifier_category_name = modifier_category_path.split('/')[1]
modifier_category_data = {
'id': modifier_category_idx,
'name': modifier_category_name,
'subcategories': [],
}
for subcategory_modifier_idx, subcategory_modifier_path in enumerate(
glob.glob(modifier_category_path + '/*.txt')):
modifier_subcategory = subcategory_modifier_path.split('/')[2].split(
'.')[0]
modifier_subcategory_data = {
'id': subcategory_modifier_idx,
'name': modifier_subcategory,
'modifiers': []
}
with open(subcategory_modifier_path, 'r') as subcategory_modifier_file:
subcategory_modifiers = subcategory_modifier_file.read(
).splitlines()
for subcategory_idx, subcategory_modifier in enumerate(
subcategory_modifiers):
subcategory_modifier_data = {
'id': subcategory_idx,
'name': subcategory_modifier
}
modifier_subcategory_data['modifiers'].append(
subcategory_modifier_data)
modifier_category_data['subcategories'].append(
modifier_subcategory_data)
modifiers.append(modifier_category_data, )
with open("modifiers.json", "w") as modifiers_file:
json.dump(modifiers, modifiers_file)