-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter.py
46 lines (39 loc) · 1.49 KB
/
filter.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
44
45
46
import json
with open("raw_stats.json") as f:
data = json.load(f)
for name,allStats in data.items():
for category, stats in list(allStats.items()):
# get the desire stats and does the dictionary need to be changed
if category == "Base":
valid = ["Base health","Movement speed"]
change = False
elif "Attack: " in category:
newKey = "Attack"
valid = ["Range","Reload time","Max. ammo"]
change = True
elif "Super" in category:
newKey = "Super"
valid = ["Range"]
change = True
else:
# delete the category that is not needed
del allStats[category]
change = False
# change the key
if change:
allStats[newKey] = allStats[category]
del allStats[category]
# float the string
for stat, value in list(stats.items()):
if (stat in valid):
try:
stats[stat] = float(value)
except ValueError:
stats[stat] = float(value.split(" ")[0])
else:
# delete the stat that is not needed
del stats[stat]
# make a new filtered json
with open("filter_stats.json", "w") as f:
jsonObject = json.dumps(data, indent=4)
f.write(jsonObject)