Add eratoho parser
Browse files- utils/eratoho_parse.py +114 -0
utils/eratoho_parse.py
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
import argparse
|
4 |
+
import tqdm
|
5 |
+
import glob
|
6 |
+
import re
|
7 |
+
|
8 |
+
from clean import clean
|
9 |
+
|
10 |
+
def format_channel(metadata):
|
11 |
+
return f'[Name: #{metadata["name"]}; Description: {metadata["topic"]}; Guild: {metadata["guild"]}]'
|
12 |
+
|
13 |
+
def worker_parse(filename, out_filename=None, **kwargs):
|
14 |
+
filtered_lines = []
|
15 |
+
with open(filename, 'r', encoding='utf-8') as f:
|
16 |
+
# data isnt json
|
17 |
+
data = f.read()
|
18 |
+
# iterate over lines
|
19 |
+
for line in data.split('\n'):
|
20 |
+
# remove left whitespace
|
21 |
+
line = line.lstrip()
|
22 |
+
# if line starts with ; then continue
|
23 |
+
if line.startswith(';'):
|
24 |
+
continue # semicolon lines are comments
|
25 |
+
dialog_starters = ['PRINTFORML ', 'PRINT ', 'PRINTL ', 'PRINTFORMW', 'PRINTW', 'PRINTFORMDL']
|
26 |
+
# inline for loop to see if line starts with dialog_starters
|
27 |
+
if any(line.startswith(dialog_starter) for dialog_starter in dialog_starters):
|
28 |
+
# remove dialog starters from line with for inline loop
|
29 |
+
for dialog_starter in dialog_starters:
|
30 |
+
if line.startswith(dialog_starter):
|
31 |
+
line = line.replace(dialog_starter, '').lstrip().rstrip()
|
32 |
+
break
|
33 |
+
line = re.sub(r'\([^)]*\)', '', line)
|
34 |
+
line = line.replace('%HIM_HER%', 'her')
|
35 |
+
line = line.replace('%HE_SHE%', 'she')
|
36 |
+
line = line.replace('%HIS_HER%', 'her')
|
37 |
+
line = line.replace('%HIMSELF_HERSELF%', 'herself')
|
38 |
+
line = line.replace('%CALLNAME:MASTER%', 'Master')
|
39 |
+
line = line.replace('%CALLNAME:TARGET%', kwargs['character'])
|
40 |
+
line = line.replace('%UNICODE%', '')
|
41 |
+
line = line.replace('%PARSE%', 'Master')
|
42 |
+
line = line.replace('%DISHNAME_TR%', 'food')
|
43 |
+
line = line.replace('%" "%', '')
|
44 |
+
line = line.replace('%TINKO%', 'member')
|
45 |
+
line = line.replace('%HIP_TR%', 'hips')
|
46 |
+
line = line.replace('%SEMEN%', 'cum')
|
47 |
+
line = line.replace('%OPPAI_DESCRIPTION_TR%', 'voluptuous breasts')
|
48 |
+
line = line.replace('%PANTSNAME%', 'skirt')
|
49 |
+
line = line.replace('%UNDER_SKIRT_DESCRIPTION_TR%', 'lacy panties')
|
50 |
+
line = line.replace('%SAMEN_DESCRIPTION%', 'hot liquid cum')
|
51 |
+
line = line.replace('%SPLIT_G%', 'Master')
|
52 |
+
line = line.replace('%SLIT%', 'slit')
|
53 |
+
line = line.replace('%LOCALS%', '')
|
54 |
+
line = line.replace('%CALLNAME:ARG%', 'your partner')
|
55 |
+
line = line.replace('%CALLNAME:%', 'your partner')
|
56 |
+
line = line.replace('%CAPITALIZE)%', 'Master')
|
57 |
+
# remove text between \@ and #
|
58 |
+
line = re.sub(r'\\@[^#]*#', '', line).lstrip().replace("\\@", "").replace(" ", " ")
|
59 |
+
if line.startswith('「') or line.endswith('」'):
|
60 |
+
line = line.replace("「", "").replace("」", "").lstrip()
|
61 |
+
if line != "":
|
62 |
+
filtered_lines.append(f'{kwargs["character"]}: {line}')
|
63 |
+
else:
|
64 |
+
if line != "":
|
65 |
+
filtered_lines.append(f'[{line}]')
|
66 |
+
|
67 |
+
with open(out_filename, 'w', encoding='utf-8') as f:
|
68 |
+
f.write(f'⁂\n[Title: eratohoTW; Description: {kwargs["character"]} dialog {kwargs["index"]}]\n⁂\n')
|
69 |
+
f.write('\n'.join(filtered_lines))
|
70 |
+
|
71 |
+
return len(filtered_lines)
|
72 |
+
|
73 |
+
|
74 |
+
def dump_stats(length, character, index):
|
75 |
+
stats = {}
|
76 |
+
if os.path.exists('stats.json'):
|
77 |
+
stats = json.load(open('stats.json', 'r', encoding='utf-8'))
|
78 |
+
else:
|
79 |
+
stats = {'eratoho': {}}
|
80 |
+
stats['eratoho'][str(character)+' - '+str(index)] = length
|
81 |
+
with open('stats.json', 'w', encoding='utf-8') as f:
|
82 |
+
json.dump(stats, f)
|
83 |
+
|
84 |
+
if __name__ == '__main__':
|
85 |
+
parser = argparse.ArgumentParser(description='Process Discord JSONs')
|
86 |
+
parser.add_argument('-i', '--in_dir', type=str, help='directory to process', required=False, default='./raw/eratoho')
|
87 |
+
parser.add_argument('-o', '--out_dir', type=str, help='directory to output', required=False, default='./data/eratoho')
|
88 |
+
parser.add_argument('-s', '--stats', action='store_true', help='write to stats', default=True)
|
89 |
+
args = parser.parse_args()
|
90 |
+
|
91 |
+
names = {
|
92 |
+
'patchouli': 'Patchouli Knowledge',
|
93 |
+
'ruukoto': 'Ruukoto',
|
94 |
+
'youmu': 'Youmu Konpaku',
|
95 |
+
'meiling': 'Hong Meiling',
|
96 |
+
'mima': 'Mima',
|
97 |
+
'kagerou': 'Kagerou Imaizumi',
|
98 |
+
'yuuka': 'Yuuka Kazami',
|
99 |
+
'kosuzu': 'Kosuzu Motoori',
|
100 |
+
'akyuu': 'Akyuu Hieda',
|
101 |
+
'shinmyoumaru': 'Sukuna Shinmyoumaru',
|
102 |
+
'clownpiece': 'Clownpiece'
|
103 |
+
}
|
104 |
+
|
105 |
+
print('wat')
|
106 |
+
|
107 |
+
if args.in_dir and args.out_dir:
|
108 |
+
if not os.path.exists(args.out_dir):
|
109 |
+
os.mkdir(args.out_dir)
|
110 |
+
files = glob.glob(args.in_dir+'/*.ERB')
|
111 |
+
for file in files:
|
112 |
+
lines = worker_parse(file, out_filename=args.out_dir+'/'+file.split('/')[-1].replace('.ERB', '.txt'), character=names[file.split('/')[-1].split('_')[0]], index=int(file.split('/')[-1].split('_')[1].split('.')[0]))
|
113 |
+
if args.stats:
|
114 |
+
dump_stats(lines, names[file.split('/')[-1].split('_')[0]].split('.')[0], file.split('/')[-1].split('_')[1].split('.')[0])
|