Skip to content

Commit

Permalink
Created custom exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
dgobalak committed Dec 25, 2021
1 parent ccf8841 commit 519d2fe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/inc/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


class NoKeywordsFoundException(Exception):
pass


class UnsupportedFileTypeException(Exception):
pass
5 changes: 4 additions & 1 deletion src/inc/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .parser import Parser
from .topic_selector import TopicSelector
from .wiki_summarizer import WikiSummarizer
from .exceptions import NoKeywordsFoundException

import os

Expand All @@ -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)

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/inc/parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import textract
import moviepy.editor as mpe

from .exceptions import UnsupportedFileTypeException

class Parser:
def __init__(self, path):
Expand All @@ -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):
Expand Down

0 comments on commit 519d2fe

Please sign in to comment.