From 7909d6d507638c03ece3a133815697e46d109263 Mon Sep 17 00:00:00 2001 From: Jaikinator Date: Mon, 19 Jun 2023 15:00:31 +0200 Subject: [PATCH] add save for different types of files --- autotranscript/transcript_exporter.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/autotranscript/transcript_exporter.py b/autotranscript/transcript_exporter.py index 37092c8..16d5e09 100644 --- a/autotranscript/transcript_exporter.py +++ b/autotranscript/transcript_exporter.py @@ -82,7 +82,6 @@ class Transcript: speaker = seq["speaker"] fstring += f"{speaker}: {seq['text']}\n" - return fstring def __repr__(self) -> str: @@ -183,6 +182,29 @@ class Transcript: def to_pdf(self, path: str) -> None: pass + def save(self, path: str, *args, **kwargs) -> None: + """ + Save transcript to file with given path and file format + + :param path: path to save file + :type path: str + :raises ValueError: if file format is unknown + """ + if path.endswith(".json"): + self.to_json(path, *args, **kwargs) + elif path.endswith(".txt"): + self.to_txt(path, *args, **kwargs) + elif path.endswith(".md"): + self.to_md(path, *args, **kwargs) + elif path.endswith(".html"): + self.to_html(path, *args, **kwargs) + elif path.endswith(".tex"): + self.to_tex(path, *args, **kwargs) + elif path.endswith(".pdf"): + self.to_pdf(path, *args, **kwargs) + else: + raise ValueError("Unknown file format") + if __name__ == "__main__": test = Transcript(json.load(open("tests/test.json", "r"))) print(repr(test))