import pandas as pd | |
df = pd.read_parquet(r'E:\tmp\互动小说\0001.parquet') | |
def clearT(): | |
import unicodedata | |
from opencc import OpenCC | |
def full2half(input_str): | |
return ''.join([unicodedata.normalize('NFKC', char) for char in input_str]) | |
cc = OpenCC('t2s') # 't2s'表示繁体转简体 | |
def _clearT(s): | |
s = cc.convert(full2half(s)) | |
return s.strip().replace('\n', '\\n') | |
return _clearT | |
clearT = clearT() | |
import json | |
z = 2767 | |
for a, b, c, d, e, f, g in df.itertuples(index=False, name=None): | |
z += 1 | |
print(z) | |
with open(r'E:\tmp\互动小说\tmp' + f'\\{z:05}_' + a + '.txt', 'w', encoding='utf-8') as file: | |
tmp = [a, b, list(c), d, e, f] | |
tmp = json.dumps(tmp, ensure_ascii=False) | |
file.write(tmp + '\n') | |
for h in g: | |
file.write('旁白:章节:' + clearT(h['chapter_title']) + '\n') | |
m = h['content'] | |
for n in m: | |
if n['role']: | |
file.write(clearT(n['role']) + ':' + clearT(n['content']) + '\n') | |
else: | |
file.write(clearT(n['content_tag']) + ':' + clearT(n['content']) + '\n') | |