Add scripts
This commit is contained in:
parent
992a748c51
commit
ba56147e95
4 changed files with 329 additions and 0 deletions
25
scripts/merge_transcriptions.py
Normal file
25
scripts/merge_transcriptions.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#!/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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue