-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate_lang.py
63 lines (50 loc) · 1.98 KB
/
update_lang.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import json
import sys
import os
import pandas as pd
def drop_na(d):
for key, value in list(d.items()):
if pd.isna(value):
del d[key]
elif isinstance(value, dict):
drop_na(value)
return d
def chara():
cdata = pd.read_json(os.path.join(KF3DB_PATH, 'mst', 'CHARA_DATA.json'))
cdata = cdata.set_index(cdata['id']).sort_index()
cdata_en = cdata[['nameEn']]
cdata = cdata[[
'name', 'nickname', 'eponymName', 'flavorText', 'animalFlavorText'
]]
pdata = pd.read_json(os.path.join(KF3DB_PATH, 'parameter.json'),
orient='index')
pdata.drop(['id', 'arts_plus'], axis=1, inplace=True)
pdata.columns = [
'art', 'art_desc', 'special', 'special_desc', 'wait', 'wait_desc',
'ability', 'ability_desc', 'kiseki', 'kiseki_desc'
]
data = cdata.join(pdata)
# old = pd.read_json(os.path.join('ja_jp', 'chara.json'), orient='index')
# diff = data[~(data == old)].dropna(how='all').dropna(axis=1, how='all')
with open(os.path.join('ja_jp', 'chara.json'), 'w', encoding='utf-8') as f:
json.dump(data.to_dict(orient='index'),
f,
indent=2,
ensure_ascii=False)
cdata_en.columns = ['name', 'nickname', 'eponymName', 'flavorText', 'animalFlavorText']
if os.path.exists(os.path.join('en_us', 'chara.json')):
old_en = pd.read_json(os.path.join('en_us', 'chara.json'),
orient='index')
old_en.drop('name', axis=1, inplace=True)
cdata_en = pd.concat([cdata_en, old_en], axis=1)
with open(os.path.join('en_us', 'chara.json'), 'w', encoding='utf-8') as f:
json.dump(drop_na(cdata_en.to_dict(orient='index')),
f,
indent=2,
ensure_ascii=False)
if __name__ == '__main__':
KF3DB_PATH = sys.argv[1]
os.chdir(os.path.dirname(os.path.abspath(__file__)))
chara()