Skip to content

Commit

Permalink
Merge pull request #7 from Mahhheshh/file-error-handling
Browse files Browse the repository at this point in the history
File error handling
  • Loading branch information
LyubomirT authored Nov 26, 2023
2 parents 6f3b973 + d8eb062 commit 7ee3944
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
15 changes: 11 additions & 4 deletions demo.py
Original file line number Diff line number Diff line change
@@ -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]

Expand Down
28 changes: 19 additions & 9 deletions lesp/autocorrect.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 7ee3944

Please sign in to comment.