-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathstringsToJson.py
53 lines (40 loc) · 1.34 KB
/
stringsToJson.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
import os
import re
import sys
import copy
import json
from openpyxl import load_workbook
WORKING_DIR = os.path.dirname(os.path.realpath(__file__))
IN_FILE = os.path.join(WORKING_DIR, "Strings.xlsx")
OUT_FILE = os.path.join(WORKING_DIR, "TheOtherRoles", "Resources", "stringData.json")
def stringToJson(in_files):
stringData = {}
for filename in in_files:
if not os.path.isfile(filename):
continue
wb = load_workbook(filename, read_only = True)
for s in wb:
rows = s.iter_rows(min_col = 1, min_row = 2, max_col = 17, max_row = None)
headers = []
for header in s[1]:
if header.value:
headers.append(header.value)
for row in rows:
name = row[0].value
if not name:
continue
data = {}
for i, string in enumerate(row[1:]):
if string.value:
# I hate excel why did I do this to myself
data[i] = string.value.replace("\r", "").replace("_x000D_", "").replace("\\n", "\n")
if data:
stringData[name] = data
with open(OUT_FILE, "w", newline="\n") as f:
json.dump(stringData, f, indent=4)
if __name__ == "__main__":
in_files = [
os.path.join(WORKING_DIR, "Strings.xlsx"),
#os.path.join(WORKING_DIR, "Strings-Dev.xlsx")
]
stringToJson(in_files)