From 519d2fe2b62a131c643c1df9fe2f8bbf5d8586a4 Mon Sep 17 00:00:00 2001 From: dgobalak Date: Fri, 24 Dec 2021 20:28:16 -0500 Subject: [PATCH] Created custom exceptions --- src/inc/exceptions.py | 8 ++++++++ src/inc/files.py | 5 ++++- src/inc/parser.py | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 src/inc/exceptions.py diff --git a/src/inc/exceptions.py b/src/inc/exceptions.py new file mode 100644 index 0000000..ec57364 --- /dev/null +++ b/src/inc/exceptions.py @@ -0,0 +1,8 @@ + + +class NoKeywordsFoundException(Exception): + pass + + +class UnsupportedFileTypeException(Exception): + pass diff --git a/src/inc/files.py b/src/inc/files.py index 94d343f..1b76e70 100644 --- a/src/inc/files.py +++ b/src/inc/files.py @@ -4,6 +4,7 @@ from .parser import Parser from .topic_selector import TopicSelector from .wiki_summarizer import WikiSummarizer +from .exceptions import NoKeywordsFoundException import os @@ -15,6 +16,8 @@ def get_summary_data(app, session) -> dict: try: fname = save_file(app) data = process_file(app, fname, session) + except Exception: + pass finally: delete_file(app, fname) @@ -56,7 +59,7 @@ def process_file(app, fname, session) -> dict: keywords = topic_selector.get_keywords() if len(keywords) == 0: - raise("No keywords found") + raise NoKeywordsFoundException("No keywords found in file") # Scrape wikipedia summary for each keyword wiki_summarizer = WikiSummarizer(keywords=keywords, lang="english", summarizer=summarizer, diff --git a/src/inc/parser.py b/src/inc/parser.py index 0b95442..ae8e124 100644 --- a/src/inc/parser.py +++ b/src/inc/parser.py @@ -1,7 +1,7 @@ import os import textract import moviepy.editor as mpe - +from .exceptions import UnsupportedFileTypeException class Parser: def __init__(self, path): @@ -17,7 +17,7 @@ def get_ftype(self): _, fext = os.path.splitext(self.path) ftypes = self.get_supported_ftypes() if fext not in ftypes: - raise KeyError("Unsupported file type") + raise UnsupportedFileTypeException("Unsupported file type") return fext def get_supported_ftypes(self):