diff --git a/demo.py b/demo.py index 955f247..7ae93f5 100644 --- a/demo.py +++ b/demo.py @@ -1,11 +1,18 @@ from lesp.autocorrect import is_correct, get_similar def load_config(): - with open("demo_config", "r") as f: - config = f.read() - return config + try: + with open("demo_config", "r") as f: + config = f.read() + return config + except FileNotFoundError: + raise FileNotFoundError("demo_config not found!") -config = load_config() +try: + config = load_config() +except FileNotFoundError as error: + print(error) + exit() # showallsimilarities="True" showallsimilarities = config.split("showallsimilarities=\"")[1].split("\"")[0] diff --git a/lesp/autocorrect.py b/lesp/autocorrect.py index c3c7d8a..9f9b1d3 100644 --- a/lesp/autocorrect.py +++ b/lesp/autocorrect.py @@ -1,18 +1,28 @@ import concurrent.futures def load_config(): - with open("config", "r") as f: - config = f.read() - return config + try: + with open("config", "r") as f: + config = f.read() + return config + except FileNotFoundError: + raise FileNotFoundError(f"Config File not found!") def load_wordlist(): - with open(wordlistpath, "r") as f: - wordlist = f.read().split("\n") - return wordlist + try: + with open(wordlistpath, "r") as f: + wordlist = f.read().split("\n") + return wordlist + except FileNotFoundError: + raise FileNotFoundError(f"{wordlistpath} not found!") -config = load_config() -wordlistpath = config.split("wordlist=\"")[1].split("\"")[0] -wordlist = load_wordlist() +try: + config = load_config() + wordlistpath = config.split("wordlist=\"")[1].split("\"")[0] + wordlist = load_wordlist() +except FileNotFoundError as error: + print(error) + exit() def is_correct(word): if word in wordlist: