auto-report-skill/scripts/merge_transcriptions.py
2026-04-21 18:09:28 +00:00

25 lines
973 B
Python

#!/usr/bin/env python3
"""Объединение транскрипций из нескольких файлов."""
import sys
import os
def merge_transcriptions(timeline_dir, output_path="merged_plain.txt"):
"""Собирает все .txt файлы в один."""
txt_files = sorted([f for f in os.listdir(timeline_dir) if f.endswith('.txt') and 'merged' not in f])
merged = []
for txt_file in txt_files:
with open(os.path.join(timeline_dir, txt_file), 'r', encoding='utf-8') as f:
content = f.read().strip()
if content:
merged.append(f"--- {txt_file} ---\n{content}\n")
with open(os.path.join(timeline_dir, output_path), 'w', encoding='utf-8') as f:
f.write('\n\n'.join(merged))
print(f"Merged {len(txt_files)} files into {output_path}")
if __name__ == "__main__":
dir_path = sys.argv[1] if len(sys.argv) > 1 else "transcription"
merge_transcriptions(dir_path)