-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmerge_csv.py
79 lines (69 loc) · 2.55 KB
/
merge_csv.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import csv
from collections import OrderedDict
debug = False
data = OrderedDict()
with open("data\\text_steam.csv", newline="", encoding="utf-8") as f:
csv_reader = csv.reader(f)
is_header = True
index = 0
for row in csv_reader:
index = index + 1
if is_header:
is_header = False
continue
key = row[0]
en = row[1]
jp = row[2]
skey = key.split("|")
json_path = skey[0][1:]
entry_wrapper_index = int(skey[1])
entry_index = int(skey[2])
if json_path not in data:
data[json_path] = {}
if entry_wrapper_index not in data[json_path]:
data[json_path][entry_wrapper_index] = {}
data[json_path][entry_wrapper_index][entry_index] = {
"en": f"{en}",
"jp": f"{jp}",
}
with open("data\\text_switch.csv", newline="", encoding="utf-8") as f:
csv_reader = csv.reader(f)
is_header = True
index = 0
for row in csv_reader:
index = index + 1
if is_header:
is_header = False
continue
key = row[0]
kr = row[3]
skey = key.split("|")
json_path = skey[0][1:]
entry_wrapper_index = int(skey[1])
entry_index = int(skey[2])
if json_path not in data:
data[json_path] = {}
if entry_wrapper_index not in data[json_path]:
data[json_path][entry_wrapper_index] = {}
if entry_index in data[json_path][entry_wrapper_index]:
data[json_path][entry_wrapper_index][entry_index]["s2_kr"] = f"{kr}"
else:
data[json_path][entry_wrapper_index][entry_index] = {
"s2_kr": f"{kr}",
}
with open("data\\text_merge.csv", "w", newline="", encoding="utf-8") as f:
csv_writer = csv.writer(f)
csv_writer.writerow(["Key", "한국어(패치)", "한국어(스위치)", "영어(스팀)", "일본어(스팀)",])
for json_path in sorted(data.keys()):
for entry_wrapper_index in sorted(data[json_path].keys()):
for entry_index in sorted(data[json_path][entry_wrapper_index].keys()):
el = data[json_path][entry_wrapper_index][entry_index]
csv_writer.writerow(
[
f"{json_path}|{entry_wrapper_index}|{entry_index}",
"",
el["s2_kr"] if "s2_kr" in el else "",
el["en"] if "en" in el else "",
el["jp"] if "jp" in el else "",
]
)