-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse5etools.py
48 lines (37 loc) · 1.29 KB
/
parse5etools.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
47
48
import json
from os import path, walk, mkdir
import re
from mappers.FiveEMapper import FiveEMapper
import pprint
CURR_DIR = path.dirname(path.abspath(__file__))
TARGET_NPC_DIR = path.join(CURR_DIR, 'hk_npcs')
SOURCE_NPC_DIR = path.join(CURR_DIR, 'source_npcs')
def main():
for root, _, files in walk(SOURCE_NPC_DIR):
for file in files:
if not file[-4:] == "json":
continue
file_name = file[:-5]
target_dir = path.join(TARGET_NPC_DIR, file_name)
if not path.exists(target_dir):
mkdir(target_dir)
with open (path.join(root, file)) as input:
npcs = json.load(input)
new_npc_bundle = list()
for npc in npcs:
mapper = FiveEMapper(npc)
new_npc = mapper.parse()
new_npc_bundle.append(new_npc)
new_npc_file_name = f"{new_npc['name']}_hk.json"
new_npc_file = path.join(target_dir, new_npc_file_name)
with open(new_npc_file, 'w') as out:
json.dump(new_npc, out, indent=2)
new_npc_bundle_file_name = f"{file.replace('.json', '')}_bundle_hk.json"
new_npc_bundle_file = path.join(TARGET_NPC_DIR, new_npc_bundle_file_name)
with open(new_npc_bundle_file, 'w') as bundle:
json.dump(new_npc_bundle, bundle, indent=2)
def parse_float(input):
from fractions import Fraction
return float(Fraction(input))
if __name__ == "__main__":
main()