Files
faster-whisper-n-ionet-llm/handlers/fileHandlers.py

24 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from pathlib import Path
from markdown_pdf import MarkdownPdf # Для аннотации типов
class FileHandlers:
# Функция сохранения файла
def saveFile(self, filename, content, output_path):
'''
Сохраняет текст или pdf из markdown_pdf в файл с указанным названием и директорией.
Args:
:param filename: название файла;
:param content: содержание файла;
:param output_path: выходная диретория файла.
'''
# Создание объекта директории
directory = Path(output_path)
filePath = directory / filename # Добавление пути директории
filePath.parent.mkdir(parents=True, exist_ok=True) # Создание директории если не существует
# Сохранение для разных типов
if type(content) == MarkdownPdf:
content.save(filePath)
elif type(content) == str:
filePath.write_text(content, encoding='utf-8')