57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
import os, re
|
|
|
|
rr = re.compile(r'[\u4e00-\u9fff]')
|
|
BASE = '/app/working/workspaces/default/check_tmp'
|
|
OUT = '/app/working/workspaces/default/publish_ready'
|
|
os.makedirs(OUT, exist_ok=True)
|
|
|
|
stories = [
|
|
('r3-yue-tang-ping-yue-qiang', '01-越躺平越强,我摆烂成了全服第一'),
|
|
('r3-shen-ming-zhong-jie', '02-神明中介:我帮神仙接单,神仙帮我躺赢'),
|
|
('r3-man-ji-da-lao-hui-xin-shou-cun', '03-满级大佬回新手村,我装了三天萌新'),
|
|
('r4-tun-jin-shou-xi-tong', '04-分手后我觉醒了吞金兽系统'),
|
|
]
|
|
|
|
for repo_dir, story_name in stories:
|
|
path = os.path.join(BASE, repo_dir)
|
|
ch_files = sorted([f for f in os.listdir(path) if f.endswith('.md') and f.startswith('第')])
|
|
|
|
intro = ''
|
|
for f in os.listdir(path):
|
|
if '简介' in f:
|
|
with open(os.path.join(path, f), 'r', encoding='utf-8') as fp:
|
|
intro = fp.read().strip()
|
|
|
|
parts = [story_name + '\n']
|
|
if intro:
|
|
parts.append('【简介】\n' + intro + '\n')
|
|
|
|
for f in ch_files:
|
|
with open(os.path.join(path, f), 'r', encoding='utf-8') as fp:
|
|
c = fp.read().strip()
|
|
# 处理标题
|
|
lines = c.split('\n')
|
|
# 清理文件头部的# 标题行
|
|
clean_lines = []
|
|
for l in lines:
|
|
if l.startswith('# '):
|
|
continue # 去掉markdown标题
|
|
clean_lines.append(l)
|
|
parts.append('\n'.join(clean_lines))
|
|
|
|
all_text = '\n\n'.join(parts)
|
|
total_h = len(rr.findall(all_text))
|
|
|
|
out_fn = story_name + '.txt'
|
|
out_path = os.path.join(OUT, out_fn)
|
|
with open(out_path, 'w', encoding='utf-8') as f:
|
|
f.write(all_text)
|
|
|
|
print(f'OK: {story_name}')
|
|
print(f' 汉字: {total_h}')
|
|
print(f' 文件: {out_path}')
|
|
print()
|
|
|
|
print('全部4部发布文件已生成!')
|